Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: A TRUE-once variable

by clintp (Curate)
on Dec 05, 2001 at 21:39 UTC ( [id://129673]=note: print w/replies, xml ) Need Help??


in reply to A TRUE-once variable

Probably overkill. Try:
sub Trueonce::TIESCALAR { my $s=1; bless \$s, $_[0]; } sub Trueonce::FETCH { my($self)=@_; local $_=$$self; $$self=0; return $_; } sub Trueonce::STORE {}
Include the code above in your program somewhere early, and use it like this:
tie $f, "Trueonce"; print $f, "\n"; # 1 print $f, "\n"; # 0 print $f, "\n"; # 0 print $f, "\n"; # 0
For some reason I'm in a tie() mood today...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-20 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found