Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
use Fcntl qw(:flock); # import LOCK_* constants if ( -e $file_banner) { open(COUNT,"$file_banner") || die print "Could not open for read"; # flock(COUNT,LOCK_EX) || die print "Could not lock"; $line = <COUNT>; # flock(COUNT,LOCK_UN) || die print "Could not unlock"; close(COUNT); print "a:$line"; $line++; print "b:$line"; open(COUNT,"+< $file_banner") || die print "Could not open for wri +te"; # flock(COUNT,LOCK_EX) || die print "Could not lock"; print COUNT "$line"; # flock(COUNT,LOCK_UN) || die print "Could not unlock"; close(COUNT); } else { open(NEW,"> $file_banner"); print NEW "0"; close(NEW); print "ffff\n\n"; } exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What is the best way to lock a counter file?
by merlyn (Sage) on Jun 25, 2000 at 16:47 UTC | |
|
Re:What is the best way to lock a counter file?
by Ovid (Cardinal) on Jun 25, 2000 at 10:37 UTC | |
|
Re: What is the best way to lock a counter file?
by Skeeve (Parson) on Jun 13, 2003 at 06:07 UTC |