in reply to i don't understand this scope behavior w/ closures and eval

A closure is only created if there is a variable in use in the subroutine

FactoryTwo simply is no closure, because you never reference any variable in there. Because of the \ before $var the variable is simply a text string without any meaning to perl. If you remove the \ before it you will see that eval "frunz" is printed again (although it won't be the closure you want, as the string with $var in it will be fixed with the value at the time FactoryTwo was called)

In the third example you reference a variable, so perl creates a closure.

  • Comment on Re: i don't understand this scope behavior w/ closures and eval