note
spurperl
So let me see if I get this correctly... Perl's foreach creates a new lexical scope (i.e. a new binding a.k.a. stack frame) at each iteration.
<br/><br/>
Python's for loop doesn't do that, and hence the difference in behavior.
<br/><br/>
Does Perl's <c>for (my $i = 0; $i < $N; ++$i)</c> behave the same way?
<br/><br/>
I wonder about the tradeoffs here. It seems likely that foreach's creation of new scopes cost something. Does it make it inherenty slower than a for loop that would not create a scope ?
719475
719480