Brian <[email protected]> asked:
> >> foreach $line (<LOGFILE>) {
> >
> > while (my $line = <$logfile>) would be a better idea than
> > foreach $line.
>
> Just curious for an explanation to this. I tend to use foreach too.
> Don't they both accomplish the same thing? :)
"foreach (<LOGFILE>)" means that the whole file will be read into memory and
split into lines before the loop commences.
The second construct will just read in a line at a time, thus trading off speed
for memory usage.
HTH,
Thomas
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/