Scope

In the introduction for this hour, you learned that subroutines are used to take pieces of code and bundle them up and give them a name. You then can use this name to execute the code whenever you need it. You can also write the code within the subroutine so that it functions autonomously. That is, you can make it run and produce its return value using nothing but its arguments, the language's built-in functions and operators, and literal expressions within it. In that case, you can reuse the subroutine in other programs, because it no longer relies on the context it's being called in; it simply takes its arguments and data defined internally and produces a return value. The subroutine becomes a black box—stuff goes in, stuff comes out—and ...

Get SAMS Teach Yourself Perl in 24 Hours THIRD EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.