Make my $sub
be a separate line. then you can refer to it
INSIDE the closure and also assign to it. You can't refer to a my
variable in the same statement that declares it.
my $sub ; $sub = sub{ blah; $sub->() }
Unfortunately that leaks memory.
use Scalar::Util qw( weaken ); my $weak_sub; my $sub = sub{ blah; $weak_sub->() }; weaken($weak_sub = $sub);
Now what's interesting about this Usenet thread is that it's a rare example of Uri Guttman and Damian Conway and getting it completely and utterly wrong...