Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Going through a big file

by LanX (Chancellor)
on Jan 17, 2013 at 12:37 UTC ( #1013769=note: print w/replies, xml ) Need Help??

in reply to Going through a big file [solved]

> First I tried the obvious

open in, shift @ARGV; for(<in>){


You will hardly find any example in the perldocs ever trying this.


open in, shift @ARGV; while (<in>){

or better

open my $in, '<', shift @ARGV; while (my $line = <$in>){


your code is semantically equivalent to

my @temp_list=<in>; for(@temp_list){
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

Replies are listed 'Best First'.
Re^2: Going through a big file
by Chuma (Acolyte) on Jan 17, 2013 at 14:05 UTC
    Oh! Well, that explains it. Thanks very much!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013769]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2017-07-24 05:14 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (348 votes). Check out past polls.