[comp.lang.perl] Bug in perl3pl44?

darrylo@hpnmdla.HP.COM (Darryl Okahata) (02/02/91)

     In perl 3 pl 44, Can a filehandle be passed by reference be opened
in a subroutine and be passed back to the caller?  I have a subroutine
that opens a filehandle passed by reference and passes it back to the
caller.  However, when I use the filehandle in the caller, it's as if
the filehandle was never opened.

     Here's a short example:

-------------------------------------------------------------------------------
#! /usr/bin/perl
#
# This perl script should create a file called "foofile" in the current
# directory, and the file should contain a couple lines of text.
# However, it doesn't.
#

$file = "foofile";
&open_file(*output, $file);
print output "foo1\n";
print output "foo2\n";
close(output);

exit 1;

###############################################################################

sub open_file
{
	local(*output2, $file) = @_;

	open(output2, ">$file") || die "Can't open $file";
}
-------------------------------------------------------------------------------

     Am I doing something stupid, or is this a bug?  I'm running perl on
an HP375 running HP-UX 7.0.

     -- Darryl Okahata
	UUCP: {hplabs!, hpcea!, hpfcla!} hpnmd!darrylo
	Internet: darrylo%hpnmd@hp-sde.sde.hp.com

tchrist@convex.COM (Tom Christiansen) (02/02/91)

Your example works fine for me at the stated patchelvel.  I get
the output.  You might use indirect filehandles as a workaround:

    &openfile('output',$file);

    sub openfile {
	local($fh, $name);
	open($fh, $name) || ...
    } 


--tom

(That's on a Convex 220, O/S version 9.0, gcc v1.39).
--
"Hey, did you hear Stallman has replaced /vmunix with /vmunix.el?  Now
 he can finally have the whole O/S built-in to his editor like he
 always wanted!" --me (Tom Christiansen <tchrist@convex.com>)

darrylo@hpnmdla.HP.COM (Darryl Okahata) (02/03/91)

In comp.lang.perl, tchrist@convex.COM (Tom Christiansen) writes:

> Your example works fine for me at the stated patchelvel.  I get
> the output.  You might use indirect filehandles as a workaround:

     Oops.  False alarm.  Stupid me had a copy of perl3pl18 earlier in
my path (strange, I thought that pl18 didn't have pass-by-reference -- I
guess it does).

     Sorry about the confusion.

     -- Darryl Okahata
	UUCP: {hplabs!, hpcea!, hpfcla!} hpnmd!darrylo
	Internet: darrylo%hpnmd@hp-sde.sde.hp.com