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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Large file processed line by line
by coolmichael (Deacon) on Jun 19, 2001 at 07:01 UTC | |
by mirod (Canon) on Jun 19, 2001 at 09:54 UTC | |
by btrott (Parson) on Jun 19, 2001 at 07:19 UTC |
In Section
Seekers of Perl Wisdom