Syntactic Confectionery Delight | |
PerlMonks |
Re: non-global $/by halley (Prior) |
on Jun 22, 2005 at 13:37 UTC ( [id://469007]=note: print w/replies, xml ) | Need Help?? |
Well, that's exactly what local does. Think of each variable name as referring to a stack of variables instead of just one. The local keyword pushes on a new value for a while, and at the end of its scope, the top value is popped and discarded. Other subroutines which might use that same variable will still see the top value.
All of the built-in "punctuation" variables are globals, not package variables. The exception are the two "default" variables, $_ and @_, which (1) get localized values automatically in many situations, and (2) assume the 'main::' package if not otherwise specified. To avoid the problem, don't do a local and call subroutines that are outside your control. The need to redefine $/ or other built-in vars should be really confined to one or two low-level statements which use those variables to tune their behavior. --
In Section
Seekers of Perl Wisdom
|
|