|
|
| "be consistent" | |
| PerlMonks |
Re: Going through a big fileby LanX (Monsignor) |
| on Jan 17, 2013 at 12:37 UTC ( #1013769=note: print w/ replies, xml ) | Need Help?? |
|
> First I tried the obvious
Obvious? You will hardly find any example in the perldocs ever trying this. Rather
or better
Explanationyour code is semantically equivalent to
slurping the whole file as a first step. for expects a list and evaluates in list context¹, so it's greedily swallowing all at once. But while iterates in scalar context, that is line by line (as defined by '$/') Cheers Rolf ¹) with a little magical exception in recent Perl versions (>= 5.8 ?) regarding ranges, which isn't relevant here
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||