in reply to Large file processed line by line
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:
Depending on your situation, you might also want to check out the -p and -n command line flags to perl (perlrun).open FH, "foo" or die "Can't open foo: $!"; while (<FH>) { ## current line is in $_, process it } close FH or warn "Error closing foo: $!";
If these are files specified on the command line, you can use the special construct:
This might be useful in a situation likewhile (<>) { ## line is in $_ }
to process each of the files on the command line.$ process.pl foo.txt bar.txt baz.txt
In Section
Seekers of Perl Wisdom