Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How to get variable evaluation in anonymous subroutines declaration

by mpeever (Friar)
on Jan 21, 2009 at 20:27 UTC ( [id://737938]=note: print w/replies, xml ) Need Help??


in reply to How to get variable evaluation in anonymous subroutines declaration

It's important to remember that closures close over variables, not values. So if the variable changes in the enclosing scope, those changes are reflected in the closure.

Copying the variable before using it essentially works around the concept of closure by creating a new variable in the function, which is in a "closer" scope. I personally think this is the best method to work around this behaviour, if that's what you want to do.

  • Comment on Re: How to get variable evaluation in anonymous subroutines declaration

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found