in reply to static variable hack
When my is encountered at run-time, a directive is placed on the stack to clear the variable. Since you're not executing my, the directive is not placed on the stack, so the variable doesn't get cleared.
The docs warn against using this side-effect of internal mechanics. (Emphasis in original.)
Note: The behaviour of a my statement modified with a statement modifier conditional or loop construct (e.g. my $x if ...) is undefined.
If you wish to have a static variable, use the following. (Surrounding curlies are optional.)
{ my $static; sub func { ... } }
See recent thread Lexical scope variable is not undef'ed.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: static variable hack (BEGIN)
by tye (Sage) on Oct 29, 2007 at 22:44 UTC | |
Re^2: static variable hack
by InfiniteLoop (Hermit) on Oct 29, 2007 at 20:15 UTC | |
by ikegami (Patriarch) on Oct 29, 2007 at 20:19 UTC | |
by InfiniteLoop (Hermit) on Oct 29, 2007 at 20:22 UTC | |
by ikegami (Patriarch) on Oct 29, 2007 at 20:31 UTC |