in reply to Re: (Ovid -flock) Re: File Use
in thread File Use
Just be sure not to forget to unlock the file when done. Plus, my code above is for appending, which is what I suspect you want.use Fcntl ':flock'; # import LOCK_* constants my $filename = "somefile.txt"; open FILE, ">>$filename" or die "Cannot open $filename for writing: $! +"; flock FILE, LOCK_EX or die "Cannot get exclusive lock on $filenam +e: $!";
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|