Hi,
as suggested by hippo, your SubOut will read the whole file on its first call, and that's probably not what you want. But you don't say enough for me to really understand what you really want.
As a couple of side notes, I would strongly suggest that you use lexical filehandles (rather than bare word filehandles, as this would make your life much easier if you want to pass the file handle to a subroutine:
open my $F, "<", $file or die;
Now, you can pass the filehandle as an argument to a subroutine just as a normal variable.
I would also suggest that you use more idiomatic Perl, because idiomatic constructs are battle tested and avoid common traps. For example, to read a file
open my $F, "<", $file or die;
while (my $line = <$F>) {
if ($line ...) {
# ...
}
}
HTH.
|