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

Thank you SO much mirod for the quick reply :-)

After literally searching everywhere and reading everything I could get my hands on, I finally get it!! :-) Of course thanks to you, perlmonks.org, and KM for the reply to the tutorial.

Have a wonderful week ... Thank you again

Replies are listed 'Best First'.
Re: Re: Re: Flocking .. insanity is close.
by Anonymous Monk on Mar 13, 2001 at 03:32 UTC
    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";