good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: How to get variable evaluation in anonymous subroutines declarationby mpeever (Friar) |
on Jan 21, 2009 at 20:27 UTC ( [id://737938]=note: print w/replies, xml ) | Need Help?? |
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.
In Section
Seekers of Perl Wisdom
|
|