in reply to Re: Re: Flocking .. insanity is close.
in thread Flocking .. insanity is close.

Sorry to bother anyone again, but please help, this method is still wiping my file clean!? I have done it exactly as the example and it doesn't seem to work.

It would mean a great deal to me if you could help.

Thank you so much.

Here is a small example -- thank you again :)

#!/usr/local/bin/perl -wT # Flocking test print "Content-type: text/html\n\n"; use Fcntl qw(:flock); my $file = 'test_lock.txt'; my $SEMAPHORE = $file . '.lck'; unless (-e "$file") { open(FILE,">$file") or die "Reason: $!"; print FILE "1"; close(FILE); } open(SEM, ">$SEMAPHORE") or die "$SEMAPHORE: $!"; flock(SEM, LOCK_SH) or die "flock() failed for $SEMAPHORE: $!"; open (FILE, "$file") or die "Can't open $file: $!"; $count = <FILE>; close FILE; sleep 5; close SEM; $count++; open(S, ">$SEMAPHORE") or die "$SEMAPHORE: $!"; flock(S, LOCK_EX) or die "flock() failed for $SEMAPHORE: $!"; open (FH, ">$file") or die "Can't open $file: $!"; print FH $count; close FH; sleep 5; close S; print "You have been here <B>$count</B> times!\n";