in reply to Re: Last undefines a for loop's itererator?
in thread Last undefines a for loop's itererator?

Some additional comment on this: you really don't want $picture to be set outside the loop. It would make debbuging really hard.

As [id://dave_the_m] said: it is an alias. Meaning if you do $picture = "something else"; then the original value will change. Limiting the effect of the alias to the foreach-block (and everything that is called via the foreach-block and still is in the lexical-scope of the variable) is a really good thing. (Because it reduces the code you need to look at when debugging.)

Also note that it is not last that undefines it. For example: for my $x (0 .. 3) { } print $x;==> it won't print 3.

(Ofcourse in your example you won't see the difference after doing an assignment because you are using a temporary list.)(It does matter. Sort seems to return an alias.)

Update: added comment about last
Update2: stroke some incorrect text.