Good question. foreach my $line(<INFILE>){} reads the entire file into an anonymous array, aliasing each element in turn to $line. while (my $line = <INFILE>){} reads the file one line at a time, storing each in turn in $line.
The foreach version must allocate more memory than the while loop, which is a bit slower. The tradeoff is up to you.
Update: ++chromatic points out that foreach iterates over a list, not an anonymous array.
After Compline,
Zaxo
In reply to Re: foreach question
by Zaxo
in thread foreach question
by glwtta
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |