in reply to Re: About "state" variables in Perl 5.10
in thread About "state" variables in Perl 5.10
The main difference I see is that the initialization of state variables only happens when the function is called
Yes, that is a good difference. Thanks!
Consider also:print counter(), "\n"; { my $count = 0; sub counter { $count++ } } print counter(), "\n"; __END__ 0 0
This one is easy to overcome, just putting the code in a BEGIN block:
citromatikprint counter(), "\n"; BEGIN{ my $count = 0; sub counter { $count++ } } print counter(), "\n"; __END__ 1 0
In Section
Seekers of Perl Wisdom