in reply to Count number of lines in a text file

Here's another variation that gets rid of a few lines:
open (FILE, $ARGV[0]) or die "Can't open '$ARGV[0]': $!"; $lines++ while (<FILE>); close FILE; print "$lines\n";

Replies are listed 'Best First'.
Re^2: Count number of lines in a text file
by davidrw (Prior) on Mar 23, 2006 at 20:45 UTC
    don't need $lines -- $. does it for you (see perlvar)
    perl -le 'open FILE, "/etc/passwd"; @_=<FILE>; print $.'
    And (similar to QM's golf reply:
    perl -lne 'END{print $.}' /etc/passwd