Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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

Comment on Re: Going through a big file
Select or Download Code
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2015-11-30 09:20 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (768 votes), past polls