in reply to Lexical scope variable is not undef'ed

The pad entry for $var is cleared by a directive placed on the stack by my at run-time. Since you never execute the my at run-time, the directive is never created, so $var is never cleared.

The "trick" relies on undocumented internal implementation details, thus its use is discouraged. If you wish to create a "static" variable, then use

{ my $var; sub func { ... } }

(Outer curlies optional.)

Replies are listed 'Best First'.
Re^2: Lexical scope variable is not undef'ed
by grinder (Bishop) on Oct 22, 2007 at 17:46 UTC

    And the code to do this in 5.10 will be

    sub func { state $var; }

    but I know you know I knew you knew this already :)

    • another intruder with the mooring in the heart of the Perl

      I didn't know, which also means you didn't know I know you knew I knew this already. :)