Hi,
I have question on processing the file handle in a subroutine.
Here is my program without subroutine:
[CODE=perl]
open FH1, "<outfile" or die "cannot open the file for reading: $!\n";
while ($line_from_out file = <FH1>) {
chomp $line_from_outf ile;
print $line_from_outf ile;
}
close FH1;
[/CODE]
I am trying to write the above program as a subroutine. So I am passing the file handle as a parameter to the subroutine. I know they are stored in the default @_ array.
But how do I process the file handle and print each line by line to STDOUT.
[CODE=perl]
open FH1, "<outfile" or die "cannot open the file for reading: $!\n";
printdevicelist (*FH1);
close FH1;
####SUBROUTINE# ###
sub printdevicelist {
my $devices = shift;
.
.
.
}
[/CODE]
I would appreciate if someone can help me here. If the contents of the file are stored in the scalar variable $devices, how is it it possible for me to print line by line???
I would appreciate your response!
Thanks,
sangith
I have question on processing the file handle in a subroutine.
Here is my program without subroutine:
[CODE=perl]
open FH1, "<outfile" or die "cannot open the file for reading: $!\n";
while ($line_from_out file = <FH1>) {
chomp $line_from_outf ile;
print $line_from_outf ile;
}
close FH1;
[/CODE]
I am trying to write the above program as a subroutine. So I am passing the file handle as a parameter to the subroutine. I know they are stored in the default @_ array.
But how do I process the file handle and print each line by line to STDOUT.
[CODE=perl]
open FH1, "<outfile" or die "cannot open the file for reading: $!\n";
printdevicelist (*FH1);
close FH1;
####SUBROUTINE# ###
sub printdevicelist {
my $devices = shift;
.
.
.
}
[/CODE]
I would appreciate if someone can help me here. If the contents of the file are stored in the scalar variable $devices, how is it it possible for me to print line by line???
I would appreciate your response!
Thanks,
sangith
Comment