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


in reply to (tye)Re2: A Real Closure
in thread Unusual Closure Behaviour

I think that the important thing about closures is being able to call the same code but have it use different variables (without passing them in as arguments).

No. You are just confusing a useful use of closures for a definition of what they are.

A closure is simply a function that refers to a free lexical variable. In the code { my $x=0; sub foo { $x } } foo() is a closure; it just isn't a very useful one. In Perl, named closures are good for simulating static variables, but not much else (that I can think of.)

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