Think about Loose Coupling | |
PerlMonks |
Re^5: Lexical closuresby ig (Vicar) |
on Oct 26, 2008 at 01:37 UTC ( [id://719597]=note: print w/replies, xml ) | Need Help?? |
Using my on for/foreach loop variables is not merely making explicit the implicit localization that is provided by the loop: the new lexical variable is distinct from any variable of the same name (lexical or not) in the surrounding scope. Note the difference in the following example:
Which produces:
After both foreach loops the global $n remains unchanged but within the first (my not used) the global is affected while within the second (my is used) the global is not affected.
In Section
Seekers of Perl Wisdom
|
|