in reply to Re: 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
package Extra; use Symbol; sub open { my ( $fh, $direction, $filename ) = @_; $$fh = Symbol::gensym; open ( $$fh, $direction, $filename ); } 1;
I think this should work without explicit references:
sub open { my (undef, $direction, $filename)=@_; $_[0]=Symbol::gensym; open ($_[0],$direction,$filename); }
The trick is not to copy the alias in @_, but to directly use the alias. Maybe you need to extend open to have a prototype of ($$$).
Anyway, I would prefer a modified open function to return a handle or undef instead of a boolean, so:
sub open { my ($direction,$filename)=@_; open my $h,$direction,$filename or return; # alternatively: or die "Can't open $filename: $!"; return $h; }
Alexander
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Looking for suitable spells to get open to return a filehandle from a module
by AnomalousMonk (Archbishop) on Nov 28, 2016 at 07:02 UTC | |
by afoken (Chancellor) on Dec 03, 2016 at 16:58 UTC | |
by pryrt (Abbot) on Dec 05, 2016 at 21:40 UTC | |
Re^3: Looking for suitable spells to get open to return a filehandle from a module
by Laurent_R (Canon) on Nov 28, 2016 at 07:26 UTC |