hey you name them, they are not anonymous! ; )
Not when its compiled, and that makes a difference.
>perl -c -we"sub outer { my $x; sub inner { $x } inner() }" Variable "$x" will not stay shared at -e line 1. -e syntax OK >perl -c -we"sub outer { my $x; local *inner = sub { $x }; inner() }" -e syntax OK
And yeah, it's effectively a named sub thereafter. That's a bonus.
I'd rather prefer this construction
I usually use inner subs for recursive functions, and my would cause a memory leak there. It also needlessly complicates the calling syntax.
sub outer { ... my $helper; $helper = sub { # $helper references helper sub ... $helper->(); # helper sub references $helper ... }; ... }
Cyclic reference ⇒ memory leak.
In reply to Re^3: sub fuction inside sub functioin?
by ikegami
in thread sub fuction inside sub functioin?
by deewanagan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |