CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
(In)efficient way of counting linesin a file?

 



PerlyDan
New User

Nov 3, 2003, 7:00 AM

Post #1 of 3 (487 views)
(In)efficient way of counting linesin a file? Can't Post

Hi,

This code seems to be taking a long time to execute. I want to count the number of lines in a set of files. Each file is about 3 million lines each. Is the code VERY inefficient? Would there be a better way of doing this? (Running on Win 2000).

Thanks,

Dan


Code
 open(LIST, "intfileList.txt")||die "$!: "."intfileList.txt\n"; 
open OUT, ">RowCounts.txt";
foreach(<LIST>){
chomp $_;
open(FILE,"$_") or print OUT "$!: "."$_\n";
if (-e $_){
@arr=<FILE>;
$count=@arr;
print OUT "$_ = $count\n";
}
}



PerlyDan
New User

Nov 3, 2003, 7:05 AM

Post #2 of 3 (486 views)
Re: [PerlyDan] (In)efficient way of counting linesin a file? [In reply to] Can't Post

p.s. Each line is about 300 bytes in length.



D.


KevinR
Veteran


Nov 3, 2003, 10:26 AM

Post #3 of 3 (482 views)
Re: [PerlyDan] (In)efficient way of counting linesin a file? [In reply to] Can't Post

this might help:



http://www.perldoc.com/perl5.8.0/pod/perlfaq5.html#How-do-I-count-the-number-of-lines-in-a-file-
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives