in reply to a problem with a filehandle reference

If you would like to make life more simple, you should use either IO::File or Filehandle or Symbol::gensym, as in the following.
use IO::File (); # assuming LOCK_FILE is a constant with the filename my $fh = IO::File->new( LOCK_FILE, 'w' ); # now you can pass $fh directly to your sub # as in code_lock( $fh ); # sub code_lock { my $fh = shift(); }
You could also create the same sort of thing with Filehandle or with the following code.
use Symbol(); my $fh = Symbol::gensym(); open($fh,">".LOCK_FILE); # pass it as in the above

Replies are listed 'Best First'.
Re: Re: a problem with a filehandle reference
by plazm (Initiate) on Apr 19, 2001 at 23:43 UTC
    Thanks! This should simplify the things. I am just really wondering why the approach doesn't work with filehandles. Is there something wrong with attr or am I doing stupid things? A.
      Without experimenting, you may need to do things like
      local *FH = \$this->{FL}; flock FH, LOCK_EX;
      or
      flock { $this->{FL} }, LOCK_EX;
      You have the same types of problems when trying to print on a handle stored in a hash.