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. Subroutines also allow you to take the code within the subroutine and make it function autonomously. That is, you can make it run simply by using its arguments, the language's built-in functions, and expressions to produce a return value. You can then reuse the function in other programs because the function no longer relies on what context it's being called in; it simply takes its arguments, data internally, and produces a return value. The function becomes a black box—stuff goes in, stuff comes out—and you don't care what happens on ...
Get Sams Teach Yourself Perl in 24 Hours 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.