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
In reply to Re^2: Looking for suitable spells to get open to return a filehandle from a module
by afoken
in thread SOLVED: Looking for suitable spells to get open to return a filehandle from a module
by talexb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |