in reply to Re^2: Tricky scope problem
in thread Tricky scope problem

It's done this way to allow for the following magic:

> perl -e '@arr = (1,2,3);$_++ foreach @arr;print @arr,"\n"' 234

By aliasing the loop variable, we gain the power to use foreach (and grep and map...) to create simple list operations without dealing with index syntax.

Replies are listed 'Best First'.
Re^4: Tricky scope problem
by lostjimmy (Chaplain) on Apr 11, 2009 at 15:50 UTC
    Thanks, kennethk. I understand very well the aliasing provided by the loop variable. I just hadn't understood why it became implicitly localized to the loop. AnomalousMonk explained it perfectly, though.