in reply to Re^8: sub fuction inside sub functioin?
in thread sub fuction inside sub functioin?
Lexicals are captured (counts as a reference), but package variables are not.
When using a lexical var, the var refers to the helper and the helper refers to the var via its pad. A cyclic reference exists.
When using a package var, the var refers to the helper but the helper doesn't refer to the var. It finds it via its symbol name when it's needed. No cyclic reference exists.
And no, exiting the scope isn't sufficient to break the cycle. Seeing two references to $inner (outer's and inner's pads) when inner exits, inner creates a new SV and aliases $inner to it. The SV still exists anonymously since outer's pad still refers to it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^10: sub fuction inside sub functioin?
by LanX (Saint) on Dec 08, 2008 at 11:10 UTC | |
by ikegami (Patriarch) on Dec 08, 2008 at 13:20 UTC | |
by LanX (Saint) on Dec 08, 2008 at 14:16 UTC | |
by ikegami (Patriarch) on Dec 08, 2008 at 17:08 UTC |