[plug] perl flock question

ryan at is.as.geeky.as ryan at is.as.geeky.as
Wed Nov 6 13:46:14 WST 2002


> is this the correct usage of flock?
>
> open(FILE,">$file");
> flock (COUNTER, 2);
> print FILE "$in{stuff}|$in{otherstuff}";
> flock (FILE, 8);
> close(FILE);

I use it like this (this is in update mode for my script, but the same
applies regardless):

use Fcntl ':flock';
open(FILEHANDLE, "+< $file") or die "Error opening file: $!";
flock(FILEHANDLE,LOCK_EX) or die "Error locking file: $!";
# do di doo
flock(FILEHANDLE,LOCK_UN) or die "Error unlocking file: $!";
close(FILEHANDLE);

I have no idea how 'correct' either of these are though.

Ryan



More information about the plug mailing list