Function Footnotes
Now that you know about scope, there are some things that can only be done effectively with scope. One is recursive functions, and the other is the use strict Perl statement that enables a stricter Perl, possibly preventing you from making mistakes.
Declaring Variables local
Perl version 4 didn't really have "private" variables. Instead, Perl 4 had variables that were "almost" private. This concept of "almost" private variables is still around in Perl 5. You declare these variables by using the local operator, as in this example:
sub myfunc { local($foo)=56; # rest of function… }
In the preceding snippet, $foo is declared to be local to the myfunc() subroutine. A variable that has been declared with local acts almost identically ...
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.