Don't ask to ask, just ask | |
PerlMonks |
Re:What is the best way to lock a counter file?by Ovid (Cardinal) |
on Jun 25, 2000 at 10:37 UTC ( [id://19741]=note: print w/replies, xml ) | Need Help?? |
It's difficult to tell what the error is if you don't supply
us with the actual error message. If the file is on a
network file system, flock is unlikely to work.
Further, flock is a polite way of requesting that
others leave the file alone. It does not actually stop the
file from being used by someone else unless they check to
see if it's locked. (That's probably not relevant to your
question, but I thought I would mention it).
Here's a somewhat cleaner version of your code (straight from the Perl Cookbook): Note that the above code will create the file for you if it does not exist. Thus, the if/else structure is eliminated. Hope this helps. Cheers!
In Section
Seekers of Perl Wisdom
|
|