Also sprach Dick Rosser:
> Sorry, I also meant to ask if there is any
> error trapping with flock. If a second person
> accesses the database befor the first persons lock
> is in place, is the database corrupted. How does one
> work around this?
You don't, but flock() does. This is exactly the scenario it is used
for. Since locks are usually only advisable, both parties accessing the
database have to use flock(). If there is already a lock on it, the
other process will block until the lock is released. You can also do
non-blocking locks in which case flock() returns a false value if the
file is already locked:
use Fcntl qw(:flock);
...
flock FH, LOCK_EX|LOCK_NB or die $!;
This can be used for allowing the waiting processes do something useful
in the meantime:
while (! flock FH, LOCK_EX|LOCK_NB) {
warn $!;
# do some useful stuff here
}
# and now we have the lock and can work with the file
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
|