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:
will never count the last line! Please do not use the above code !!!while (sysread FILE, $buffer, 4096) { $lines += ($buffer =~ tr/\n//); }
Use:
while (<FILE>) { $lines++ }
|
---|
In Section
Cool Uses for Perl