Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: File::CounterFile problems : access from mulitple scripts and zeroing counter

by Kanji (Parson)
on Sep 26, 2005 at 18:21 UTC ( #495177=note: print w/replies, xml ) Need Help??


in reply to File::CounterFile problems : access from mulitple scripts and zeroing counter

You could extend F::CF to support zeroing out the counter.

Something like...

package File::CounterFile::Resettable; use base qw( File::CounterFile ); sub reset { my($self) = @_; if ($self->locked) { $self->{'value'} = 0; $self->{updated} = 1; } else { $self->lock; $self->{'value'} = 0; $self->{updated} = 1; $self->unlock; } $self->{'value'}; # return value }

...and then later in your script...

my $count = File::CounterFile::Resettable->new("./asr_counter.txt"); $count->lock(); $count->reset(); $count->unlock();
(Code is untested, but you hopefully get the idea!)

    --k.


Update: $code =~ s/\t/ /g; # for readability.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://495177]
help
Chatterbox?
[stevieb]: wondering wtf is wrong with my brewbuild automation system. Appears as though perlbrew now asks for confirmation when uninstalling a perl. Anyone know how to shut this thing off?
[chacham]: book prop

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2017-03-26 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (315 votes). Check out past polls.