tanger has asked for the wisdom of the Perl Monks concerning the following question:
Should I lock the file like this? and is it the right way?use fcntl qw(:DEFAULT :flock); use DB_File; $lck = $path/whosonline . ".lockfile"; sysopen(DBLOCK, $LCK, O_RDONLY | O_CREAT) or die "can't open $lck: $!" +; flock(DBLOCK, LOCK_SH) or die "cant lock_sh $lck: $1"; dbmopen %who, "$path/whosonline", 0666 or die "Can't open FILENAME: $ +!\n";# open database, accessed through %mname tie %who, "DB_File", "$path/whosonline" or die "Can't open FILENAME: $ +!\n"; # open database tie hash to db $V = $who{$points}; # retrieve from database this is th +e key $who{$Account::cata_acc} = "$time"; # put value into da +tabase this is the value if (exists $who{"$Account::cata_acc"}) { # check whether in data +base } untie %who ; dbmclose %who; # close the database close DBLOCK; #done checking whosonline
Edit: 2001-03-03 by neshura
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Should I lock this DBM File?
by dws (Chancellor) on Feb 12, 2001 at 09:36 UTC | |
|
Re (tilly) 1: Should I lock this DBM File?
by tilly (Archbishop) on Feb 12, 2001 at 09:29 UTC | |
|
Re: Should I lock this DBM File?
by merlyn (Sage) on Feb 12, 2001 at 19:33 UTC |