in reply to Re: Hidden Secrets of PERL
in thread Hidden Secrets of PERL
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.
--
David Serrano
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Hidden Secrets of PERL
by bart (Canon) on Oct 12, 2006 at 11:08 UTC |