I am writing a comparefiles
subroutine in Perl that reads a line of text from one file (f1
) and then searches for it in another (f2
) in the normal O(n^2)
way.
sub comparefiles {
my($f1, $f2) = @_;
while(<f1>) {
# reset f2 to the beginning of the file
while(<f2>) {
}
}
}
sub someother {
open (one, "<one.out");
open (two, "<two.out");
&comparefiles(&one, &two);
}
I have two questions
- How do I pass the file handles to the subroutine? In the above code, I have used them as scalars. Is that the correct way?
- How do I reset the file pointer
f2
to the beginning of the file at the position marked in the comment above?