Prasad J Pandit wrote:
Hello there!
Hello,
I'm a novice perl programmer and I'm trying to pass a File-Handle to two different subroutines one after the other as follows #!/usr/bin/perl -w use strict; my $FH;
$FH is a scalar variable.
open($FH, "filename") || die "Could not open file! \n";
You can declare the scalar here if you want: open(my $FH, "filename") || die "Could not open file! \n";
func_one(\*$FH); func_two(\*$FH);
Just use the scalar: func_one($FH); func_two($FH);
exit(0); sub func_one { local * FH = $_[0];
And then store it locally like: my $FH = $_[0];
my $line; while(defined($line = <$FH>)) { printf($line); } } sub func_two { local * FH = $_[0];
my $FH = $_[0];
my $line; while(defined($line = <$FH>)) { printf($line); } }
John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>