http://www.perlmonks.org?node_id=1212245

morgon has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

can someone explain this behaviour to me:

use strict; my $i = "whatever"; for $i (1..10) { last if $i == 7; } print "$i\n"; # prints "whatever"
I had expected that within the loop the previously declared variable would be used and with each iteration it would be assigned a new value, so that after the loop it should have the new value 7.

But that's not how it works.

The loop does not seem to change the value of $i at all - but why?

Many thanks!