Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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.


Comment on Re: File::CounterFile problems : access from mulitple scripts and zeroing counter
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-12-25 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls