Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: Looking for a better way to get the number of lines in a file...

by gbarr (Monk)
on Dec 10, 2001 at 22:20 UTC ( [id://130731]=note: print w/replies, xml ) Need Help??


in reply to (RhetTbull) Re: Looking for a better way to get the number of lines in a file...
in thread Looking for a better way to get the number of lines in a file...

Reading the file line-by-line is not going to be the most efficient way, esp. if the file is large. Instead you could read the file in blocks and count the newline characters

local $/=\102400; while(<FILE>) { $count += tr/\n// }

This example reads in chunks of 100K.

  • Comment on Re: Re: Looking for a better way to get the number of lines in a file...
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://130731]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-04-23 13:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found