Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Perl >> Snippet

Count the number of lines in a file


$lines = 0;
open (FILE, $filename ) or die "Can't open `$filename': $!" ;
while ( sysread FILE, $buffer , 4096) {
    $lines += ( $buffer = ~ tr /\n//);
}
close (FILE);