There's more than one way to do things | |
PerlMonks |
Re: Why are closures cool, continued?by AidanLee (Chaplain) |
on Jan 19, 2002 at 03:04 UTC ( [id://139987]=note: print w/replies, xml ) | Need Help?? |
It really is a closure :) The key is that the array @stuff are only supposed to exist while new() is the current scope. But by declaring a subroutine reference that uses @stuff you are forcing perl to not garbage-collect it at the end of new()'s scope. However, the only way you can now touch this array which is in limbo is through the subroutine reference which you returned from the subroutine new().
In Section
Seekers of Perl Wisdom
|
|