in reply to Re: (jeffa) Re: Why are closures cool, continued?
in thread Why are closures cool, continued?
The anonymous routine (blessed or not) refers to a lexically-scoped variable in its enclosing scope. That lexically-scoped variable is magically kept alive (in the anonymous subroutine) after that enclosing scope has been exited. That is what makes an anonymous subroutine a closure.
sub makeAnonymousSub { sub { print "I am not a closure\n" } } sub makeClosure { my $x = shift; sub { print "I keep $x alive, thus I'm a closure\n" } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: (jeffa) Re: Why are closures cool, continued?
by perrin (Chancellor) on Jan 19, 2002 at 05:57 UTC |