in reply to Going through a big file [solved]
open in, shift @ARGV; for(<in>){
Obvious?
You will hardly find any example in the perldocs ever trying this.
Rather
open in, shift @ARGV; while (<in>){
or better
open my $in, '<', shift @ARGV; while (my $line = <$in>){
your code is semantically equivalent to
slurping the whole file as a first step.my @temp_list=<in>; for(@temp_list){
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Going through a big file
by Chuma (Scribe) on Jan 17, 2013 at 14:05 UTC |