in reply to Re^2: loop surprise
in thread loop surprise

> get the rationale for doing it this

This was often discussed already, have a look into the archives if you want more details.°

IIRC it's because this behaviour of localizing the loop var is older (read Perl4) than lexicals.

Rule of thumb: never try to reuse an outer var as loop var in foreach... see also PBP advice to always for my $x (...) .

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery

°) it leads to very confusing results if the loop creates subs closing over the loopvar.