in reply to Nested sub's beget undead variables?

Named functions all have the same visibility. Their bindings for lexicals get created at compilation time, so the inner function can't share the lexical bindings of the outer function. (This is a huge oversimplification, but is essentially true as far as it matters now.)

One way to alleviate this is to introduce a lexical scope external to both function4 declarations:

{ my ($v1, $v2); sub outer_function { ... } sub inner_function { ... } }

Otherwise you could make inner_function() an anonymous function so that it always binds those two lexicals to the current lexical scope of outer_function().

Replies are listed 'Best First'.
Re^2: Nested sub's beget undead variables?
by Nivlem (Initiate) on Nov 10, 2010 at 20:03 UTC

    Thanks chromatic; that explains it. Love your book, by the way.

    N