The stupid question is the question not asked | |
PerlMonks |
Re^6: why need my in a foreach loop? (Aliasing)by LanX (Saint) |
on Dec 08, 2010 at 13:00 UTC ( [id://876015]=note: print w/replies, xml ) | Need Help?? |
Hi Gabor >However I'd be interested to know in what case would you really want to write such code? As already said my is much younger than foreach and it's consistent and backward compatible. While looping over localized globals could also be done with an extra local $packvar=$lex_for_var, the aliasing effect of foreach can't be achieved in any other way in core Perl.
For a detailed discussion, see How do closures and variable scope (my,our,local) interact in perl?.
Cheers Rolf UPDATE: expanded code, fixed typos
In Section
Seekers of Perl Wisdom
|
|