Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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 surveying the Monastery: (7)
As of 2014-08-29 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (288 votes), past polls