plazm has asked for the wisdom of the Perl Monks concerning the following question:
Here comes the code:
use vars qw($LF); sub new { my $proto = shift; my $class = ref($proto) || $proto; open(FH, ">".LOCK_FILE) or die "ERROR: cannot open lock file: +".LOCK_FILE.": $!\n"; my $this = { LF => \*FH }; bless($this, $class); return $this; } .... # # code_lock() # Lock a section of code. # sub code_lock { my $this = attr shift; my $ret = flock $LF, LOCK_EX; return scalar $ret; }
This doesn't work because $FL appears to be undefined in code_lock(). If I change flock() call to the following:
this works just fine! I am really wondering what is the problem here.flock $this->{'FL'}, LOCK_EX;
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: a problem with a filehandle reference
by Rhandom (Curate) on Apr 19, 2001 at 23:39 UTC | |
by plazm (Initiate) on Apr 19, 2001 at 23:43 UTC | |
by Rhandom (Curate) on Apr 20, 2001 at 00:00 UTC | |
|
Re: a problem with a filehandle reference
by suaveant (Parson) on Apr 19, 2001 at 23:06 UTC | |
by plazm (Initiate) on Apr 19, 2001 at 23:41 UTC | |
by suaveant (Parson) on Apr 19, 2001 at 23:55 UTC | |
by plazm (Initiate) on Apr 20, 2001 at 00:06 UTC | |
by suaveant (Parson) on Apr 20, 2001 at 00:16 UTC | |
by plazm (Initiate) on Apr 20, 2001 at 00:09 UTC |