|Just another Perl shrine|
Re^6: why need my in a foreach loop? (Aliasing)by LanX (Chancellor)
|on Dec 08, 2010 at 13:00 UTC||Need Help??|
>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?.
UPDATE: expanded code, fixed typos