Thathom has asked for the wisdom of the Perl Monks concerning the following question:
With the method up above I was worried that the second user could still pick up the same ID file from the first read of the COUNT file before the first user had actually written the updated number back to it. Any ideas?#GET CURRENT NUMBER open(FH, "counter.dat"); flock(FH, 1); $id = <FH>; close(FH); #INCREASE COUNT $id++; #WRITE NUMBER BACK open(FH, "+< counter.dat"); flock(FH, 2); seek(FH, 0, 0); truncate(FH, 0); print FH $id; close(FH);
ThAtH0M
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Flock Updating Counter
by busunsl (Vicar) on Dec 06, 2002 at 10:42 UTC | |
|
Re: Flock Updating Counter
by Zaxo (Archbishop) on Dec 06, 2002 at 10:54 UTC | |
|
•Re: Flock Updating Counter
by merlyn (Sage) on Dec 06, 2002 at 17:41 UTC | |
|
Re: Flock Updating Counter
by jreades (Friar) on Dec 06, 2002 at 11:29 UTC | |
|
Re: Flock Updating Counter
by Chief of Chaos (Friar) on Dec 06, 2002 at 12:33 UTC |