Don't ask to ask, just ask | |
PerlMonks |
Re: Something like c++'s static?by Zaxo (Archbishop) |
on Aug 02, 2002 at 18:07 UTC ( [id://187169]=note: print w/replies, xml ) | Need Help?? |
Another approach in newer perls gives something that looks very C-like in use. Make foo an lvalue accessor which takes no arguments:
The BEGIN block is only needed to get the "default" value in early (completely unneeded in this simple case). In a module, you can leave 'foo' off the @EXPORT_OK list so it's perlishly private to the module package. For thread safety, you'd want the 'locked' attribute, besides 'lvalue'. Update: Added clarification on the BEGIN block, and an unwise adverb. After Compline,
In Section
Seekers of Perl Wisdom
|
|