Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
This code is my attempt to create a more robust locking mechanism. Is there anyway I can get the filename from the filehandle? I could pass it in as a parameter, but I'd rather pass as few parameters as possible.sub sleep_lock { my $FH = *{$_[0]}; my $lock_type = $_[1]; my $time = $_[2] ||5; for ( 1..$time ) { last if flock $FH, $lock_type; unless ( $_ < $time ) { die "Can't lock file: $!" }; sleep 1; } }
Are there any other problems anyone sees?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Filename from filehandle?
by clintp (Curate) on Apr 24, 2001 at 04:29 UTC | |
by Xxaxx (Monk) on Apr 24, 2001 at 10:40 UTC | |
by tilly (Archbishop) on Apr 25, 2001 at 02:25 UTC | |
by clintp (Curate) on Apr 25, 2001 at 05:01 UTC |