Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by Kanji (Parson)
on Sep 26, 2005 at 18:21 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://495177]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2024-04-19 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found