in reply to Re^2: Looking for suitable spells to get open to return a filehandle from a module
in thread SOLVED: Looking for suitable spells to get open to return a filehandle from a module
What is the effect of the invocation of Symbol::gensym? This code seems to work just fine without it both with aliasing and with an automatic reference via a prototype (also minimally tested):
t_extra_open.pl:
Extra.pm:use warnings; use strict; use Extra; { my $filename = 'extra-open.txt'; Extra::open my $fh, '>', $filename or die "opening '$filename' for write: $!"; defined $fh or die "write filehandle not defined"; print $fh "Extra open works just fine \n"; print $fh "at ", scalar(localtime), "\n"; close $fh or die "closing '$filename' after write"; undef $fh; Extra::open $fh, '<', $filename or die "opening '$filename' for read: $!"; defined $fh or die "read filehandle not defined"; print '<<', <$fh>, '>>'; close $fh or die "closing '$filename' after read"; }
(Tested under ActiveState 5.8.9 and Strawberry 5.14.4.1.)package Extra; sub open { # works my (undef, $direction, $filename) = @_; return open $_[0], $direction, $filename; } # sub open (\$@) { # works # # my ($sr_fh, $direction, $filename) = @_; # # return open $$sr_fh, $direction, $filename; # # } 1;
Give a man a fish: <%-{-{-{-<
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Looking for suitable spells to get open to return a filehandle from a module
by afoken (Chancellor) on Dec 03, 2016 at 16:58 UTC | |
by pryrt (Abbot) on Dec 05, 2016 at 21:40 UTC |