2009/7/16 David Nicol <davidnicol@gmail.com>: > On Thu, Jul 16, 2009 at 9:51 AM, Rafael > Garcia-Suarez<rgarciasuarez@gmail.com> wrote: >> Ah, so you were making the assumptions that the sub to call is known >> at compile time and that it would never change during the lifetime of >> the program. This is Perl, so those are wrong assumptions :) > > anyone for "local sub" shorthand? > > $ perl -le 'sub X {"outer"} { local sub X {"inner"} print &X } print &X' > > could become equivalent to > > $ perl -le '*sub X {"outer"}; { local *X = sub {"inner"}; print &X } print &X' One problem with the bottom on older perls is it resets the method cache for all methods, twice. In newer perls I think things are better, I dont know how much. The only need for this that i know of is if you dont have Scalar::Utils::weakref() available for some reason, and you need to do a recursive closure. And i personally think that case is much easier to solve, (already (mostly?) solved actually thanks to rafael), by having a symbol which always refers to the current sub, without modifying the subs refcount. Which is more or less provided by Sub::Current. cheers, Yves -- perl -Mre=debug -e "/just|another|perl|hacker/"Thread Previous | Thread Next