http://www.perlmonks.org?node_id=272161


in reply to Re^4: Closure on Closures (beta)
in thread Closure on Closures

So is this a closure?

Uhm, yeah... at least to the same extent that my example was.

The variable bindings are not retained - because we don't get 100, 101, etc.

The binding are only retained after the first entry via the goto, at which point, the variable does increment with each successive jump back to that code.

It behaves strangely. After the first jump into the code, it begins acting like a closure; the variable binding is retained. It isn't useful, in part because there is no easy way to initialize the variable first. Perl seems to initialize it to undef for us. I'm not even sure that this is the behavior I'd like to see. I figure it should either maintain the binding and act just like a named closure, or it should emit an error/warning. As it is, it works silently under strict checking and with warnings on.

-sauoq
"My two cents aren't worth a dime.";