Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: why need my in a foreach loop?

by 7stud (Deacon)
on Dec 02, 2010 at 03:46 UTC ( #874816=note: print w/ replies, xml ) Need Help??


in reply to Re^3: why need my in a foreach loop?
in thread why need my in a foreach loop?

Nice catch.

If you switched our for my in my snippet, you'd have a closure, and you'd get a different result.

Is that correct? Because the my variable would still be in scope, would the subroutine qualify as a closure? It's my understanding that a subroutine is a closure when it preserves a variable that has gone out of scope.


Comment on Re^4: why need my in a foreach loop?
Re^5: why need my in a foreach loop?
by ikegami (Pope) on Dec 02, 2010 at 16:38 UTC

    I don't know the precise definition if there is one. For practical purposes, I find it doesn't matter.

    Correction: In this case, the sub truly acts as a closure. If it didn't, it wouldn't matter if you used our or my.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-07-25 02:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls