in reply to Initialization of "local static" (style question)
If you want $myval to be private to &f, don't use our, use my in a block enclosing both, &f and $myval:
{ my $myval = myfunc(); sub f { ... }; };
Alternatively, if you are on Perl 5.10, you can use the new state keyword, which is basically the same but a bit more explicit. Also see About "state" variables in Perl 5.10 for some more discussion, also about the timing of the different initializations.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Initialization of "local static" (style question)
by rovf (Priest) on Feb 03, 2009 at 11:19 UTC | |
by massa (Hermit) on Feb 03, 2009 at 12:13 UTC | |
|
Re^2: Initialization of "local static" (style question)
by AnomalousMonk (Archbishop) on Feb 03, 2009 at 18:41 UTC |