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