in reply to Re: Re: Re: Flock Feedback
in thread Flock Feedback

Even with this approach you still would need locking.

Yes, as written. But the ">>" file mode does allow you to use something very similar to this without (additional) locking.

use IO::Handle; my $filename = '/path/to/file'; # Increment the counter (atomically, so no locking required) open(FILE, ">> $filename") or warn "Missed a count"; FILE->autoflush(1); print FILE '.'; # Ouput one (arbitrary) byte my $counter= tell(FILE); close FILE;

Now, if you reset your counters every so often, this can be a really nice little trick. To reset the counters, just do a unlink($filename) once a day/week/month, which also doesn't require any locking on your part! (Though the location and permissions on the counter file are a non-trivial problem so you may want to use sysopen so you can specify permission bits for the case when the file is recreated.)

        - tye (but my friends call me "Tye")