Kagami097 has asked for the wisdom of the Perl Monks concerning the following question:
Hello All,
I am facing an issue while passing an open filehandle to a subroutine .The code goes something like below.
When i execute this code , i end up losing the line that matches in the main program.How can i pass an open filehandle to a subroutine and store the line that matches in the main program.In the code above i am losing that line cause of my $s_line = <$fh>.my $in = "class.txt"; open F , $in or die; my $line =<F>; while($line){ if ($line =~ /xyz/){ SubOut(\*F); } $line =<F> ; } close F; sub SubOut{ my $fh = shift; my $s_line = <$fh>; my @ref; push (\@ref, $s_line); while($s_line){ print STDOUT $s_line; $s_line = <$fh>; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Passing a filehandle to subroutine
by hippo (Bishop) on Aug 10, 2017 at 16:17 UTC | |
Re: Passing a filehandle to subroutine
by Marshall (Canon) on Aug 10, 2017 at 22:58 UTC | |
Re: Passing a filehandle to subroutine
by Laurent_R (Canon) on Aug 10, 2017 at 22:16 UTC | |
Re: Passing a filehandle to subroutine
by GotToBTru (Prior) on Aug 10, 2017 at 18:02 UTC |
Back to
Seekers of Perl Wisdom