Re: A file-handle query
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Fri, 24 Jun 2005 03:44:15 -0700
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 .
- Follow-Ups:
- Re: A file-handle query
- From: Jeff 'japhy' Pinyan
- Re: A file-handle query
- References:
- A file-handle query
- From: Prasad J Pandit
- A file-handle query
- Prev by Date: Re: how to append blocks in same file
- Next by Date: Re: how to append blocks in same file
- Previous by thread: A file-handle query
- Next by thread: Re: A file-handle query
- Index(es):
Relevant Pages
|
|