in reply to flock till ya get it right
The truncate call is there to avoid the nasty race condition that happens when someone else manages to also open the file for writing and then writes into it prior to your getting the lock.open(FILE, ">file.dat") or die "file.dat: $!"; while ( ! flock(FILE, 2) ) { # you *might* want to consider bailing out at # some point. } truncate FILE, 0; # important! to avoid corrupted files print FILE, "blah\n"; close(FILE); }
|
|---|