Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: About "state" variables in Perl 5.10

by citromatik (Curate)
on Dec 29, 2007 at 12:58 UTC ( #659476=note: print w/replies, xml ) Need Help??


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:

print counter(), "\n"; BEGIN{ my $count = 0; sub counter { $count++ } } print counter(), "\n"; __END__ 1 0
citromatik

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://659476]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2021-05-13 20:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (142 votes). Check out past polls.

    Notices?