in reply to Re^2: recursive anonymous subroutines
in thread recursive anonymous subroutines
Hmm... probably safer to keep the reference on the call stack, thus releasing it on exit.
For example, adopting the convention that the reference is always passed as the first parameter:
..or..my @factorials = map { $_[0] ||= sub { my $factor = pop; return $factor > 1 ? &{$_[0]}($_[0],$factor-1) * $factor : 1; }; &{$_[0]}($_[0],$_)} (3,5,7,9);
sub make_call { goto $_[0]; } my @factorials = map { make_call (sub { my $factor = $_[1]; return $factor > 1 ? make_call($_[0], $factor-1) * $factor : 1; }, $_); } (3,5,7,9);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: recursive anonymous subroutines
by Daryn (Sexton) on Apr 10, 2006 at 12:05 UTC | |
|
Re^4: recursive anonymous subroutines
by runrig (Abbot) on Apr 11, 2006 at 23:26 UTC | |
by snoopy (Curate) on Apr 18, 2006 at 00:58 UTC |