"be consistent" | |
PerlMonks |
Re^2: Hidden Secrets of PERLby Hue-Bond (Priest) |
on Oct 11, 2006 at 22:58 UTC ( [id://577729]=note: print w/replies, xml ) | Need Help?? |
If the variable that is going to hold each value in an loop already exists as a lexical one (first example), foreach creates a new lexical whose scope is the loop block. If it exists as a package global (second example), foreach localizes it, thus making its scope dynamic. That's why second example's print_foo sees the dynamic content. --
In Section
Seekers of Perl Wisdom
|
|