[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Counting the number of lines in a document



At 11:18 24/04/96 -0500, "Robert A. Decker" <comrade@umich.edu> wrote:
>Is there a simple Perl command for counting the number of lines in a
>document?

In addition to Matthias' way (which I find a bit farfetched) this is the
first thing I thought about:


#! perl
while (<>) {
   $count++;
}


In plain talk: for each line, add 1 to count.

In contrast to the other replies, this has the advantage of *not* slurping
up the whole file. This way, it can handle a 5MB text file safely.


Bart




--- Embracing the KIS principle: Keep It Simple