The general idiom is to use a
while loop to iterate
over the lines in the file, reading in one line at a time
and processing it, then moving on to the next.
Something like this:
open FH, "foo" or die "Can't open foo: $!";
while (<FH>) {
## current line is in $_, process it
}
close FH or warn "Error closing foo: $!";
Depending on your situation, you might also want to
check out the
-p and
-n command
line flags to perl (
perlrun).
If these are files specified on the command line,
you can use the special construct:
while (<>) {
## line is in $_
}
This might be useful in a situation like
$ process.pl foo.txt bar.txt baz.txt
to process each of the files on the command line.