On Wed, 07 Apr 2004 13:51:03 -0500 "JupiterHost.Net" <[EMAIL PROTECTED]> wrote:
> perldoc -f flock says > > "If LOCK_NB is bitwise-or'ed with LOCK_SH or LOCK_EX then "flock" > will return immediately rather than blocking waiting for the lock > (check the return status to see if you got it)." > > So that would mean: > > use Fcntl ':flock'; > > flock(FH, LOCK_EX || LOCK_NB) or die "Lock failed $!"; > ... > flock FH, LOCK_UN; Not quite. The bitwise or operator is '|' not '||'. What you have sets the 2nd argument to true or 1 which is not what you want. > If so, does the numeric values work the same way? The numeric values work the same, but I strongly encourage use of the manifest constants. It makes the code more portable and easier to read. > flock(FH, 1 || 4) or die "Lock failed $!"; > ... > flock FH, 8; > > correct? > > If you do the (LOCK_EX || LOCK_NB) or (1 || 4) is the return code > different depending on the type of lock received? > > IE > my $rc = flock(FH, LOCK_EX || LOCK_NB); > if($rc == 4) { warn "rats! Exclusive lock not granted, oh well..."; > } if(!$rc) { die "Could not get lock no how mr flock guy!"; } The return code with LOCK_NB is false if the file is locked by another process, true is you got the lock. $! holds the appropriate error message. -- Smoot Carl-Mitchell Systems/Network Architect email: [EMAIL PROTECTED] cell: +1 602 421 9005 home: +1 480 922 7313 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>