Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Count the number of lines in a file

by nobull (Friar)
on May 25, 2004 at 17:11 UTC ( [id://356297]=note: print w/replies, xml ) Need Help??


in reply to Count the number of lines in a file

You can get the size of a file with -s but that's not the same as the number of characters unless the file uses an encoding that is always one byte per character.
#!/bin/perl use strict; use warnings; my $chars = 0; my $lines = 0; while (<>) { $chars += length; $lines ++; } print "$chars $lines\n";
You can call this script with the files as standard input and standard output.

If you want to open the files within the Perl script instead use the open() function.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2024-04-23 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found