目的:统计指定文件的行数。
$filename = 'test.file';$lines = 0;open(FILE, $filename) or die "Can't open `$filename': $!";while (sysread FILE, $buffer, 4096) { $lines += ($buffer =~ tr/\n//);}close FILE;print $lines;
one line code on command line :
perl -ne "print $. if eof" filename
更改解决方案参见:
[url]http://bbs.chinaunix.net/archiver/?tid-521001.html[/url]
原文:
[url]http://faq.perl.org/perlfaq5.html#How_do_I_count_the_n[/url]