Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Last undefines a for loop's itererator?

by Animator (Hermit)
on Nov 12, 2005 at 11:20 UTC ( [id://507965]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://507965]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-24 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found