in reply to Re^2: sub fuction inside sub functioin?
in thread sub fuction inside sub functioin?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: sub fuction inside sub functioin?
by LanX (Saint) on Dec 07, 2008 at 21:18 UTC | |
by ikegami (Patriarch) on Dec 07, 2008 at 23:20 UTC | |
by LanX (Saint) on Dec 08, 2008 at 02:05 UTC | |
by ikegami (Patriarch) on Dec 08, 2008 at 02:52 UTC | |
by LanX (Saint) on Dec 08, 2008 at 02:56 UTC | |
| |
by gone2015 (Deacon) on Dec 08, 2008 at 02:08 UTC |