kiseok7 has asked for the wisdom of the Perl Monks concerning the following question:
this is my file locking function..
but;
it seem to be failure often.
what is problem with my function...!?
and how about you, all?
show me the best file locking example..
thanks
#!perl my $file = "hanul.txt"; lock($file); open FILE, ">$file"; print FILE "you're locking...\n"; close FILE; unlock($file); # LoCk sub lock{ my $lFile = shift; my $LockFile = "$lFile.lock"; my $EndTime = time + 45; while (-e $LockFile && time < $EndTime) { } if (!open (LOCK,">$LockFile")){ return 0; } else{ chmod 0666, $LockFile; $locked = 'Y'; } } # uNLocK sub unlock { my $lFile = shift; my $LockFile; if ($locked eq 'Y'){ $LockFile = "$lFile.lock"; close (LOCK); if (-e $LockFile) { unlink ($LockFile); } $locked = 'N'; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: file locking problem!
by LD2 (Curate) on Jun 29, 2001 at 18:27 UTC | |
|
Re: file locking problem!
by RatArsed (Monk) on Jun 29, 2001 at 18:22 UTC | |
by kiseok7 (Beadle) on Jun 29, 2001 at 18:27 UTC | |
by RatArsed (Monk) on Jun 29, 2001 at 18:28 UTC | |
by tye (Sage) on Jun 29, 2001 at 21:16 UTC | |
|
Re: file locking problem!
by Anonymous Monk on Jun 29, 2001 at 21:53 UTC | |
|
Re: file locking problem!
by Chady (Priest) on Jun 29, 2001 at 18:23 UTC |