in reply to Re^2: modules, exporting, and indirect filehandles
in thread modules, exporting, and indirect filehandles

It looks fine, and it works for me when I run that. Are you sure you're using the files you think you are using.

By the way, \* in return \*$fh; is useless. return $fh; will return the same thing.

Starting with Perl 5.6, open accepts the mode and file name as seperate arguments. It's safer to use the three argument form and concatenating the mode and file name:

sub open_file { my ($mode, $file) = @_; my $fh = gensym(); open $fh, $mode, $file or croak("could not open '$file': $!"); return $fh; }

Replies are listed 'Best First'.
Re^4: modules, exporting, and indirect filehandles
by chromatic (Archbishop) on Aug 09, 2005 at 20:31 UTC

    With 5.6, there's no need to use gensym() either:

    sub open_file { my ($mode, $file) = @_; open my $fh, $mode, $file or croak("Could not open '$file': $! +"); return $fh; }
      I know. You just duplicated my first reply (except mine also supports the two-arg open). The OP stated he didn't want to use that.
Re^4: modules, exporting, and indirect filehandles
by eff_i_g (Curate) on Aug 09, 2005 at 21:11 UTC
    i thought i had replied, but apparently i forgot to follow it all the way through. thank you for your help; this is working well :)