Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Count number of lines in a text file

by Anonymous Monk
on Jan 23, 2013 at 08:53 UTC ( #1014861=note: print w/ replies, xml ) Need Help??

in reply to Count number of lines in a text file

Everybody should be aware that in an ASCII file, the last line may NOT contain a '\n' character. This means the following code:

while (sysread FILE, $buffer, 4096) { $lines += ($buffer =~ tr/\n//); }
will never count the last line! Please do not use the above code !!!


while (<FILE>) { $lines++ }

Comment on Re: Count number of lines in a text file
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2015-08-29 19:15 GMT
Find Nodes?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...

    Results (344 votes), past polls