perl faq 学习之统计文件行数
目的:统计指定文件的行数。$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
更改解决方案参见:
http://bbs.chinaunix.net/archiver/?tid-521001.html
原文:
http://faq.perl.org/perlfaq5.html#How_do_I_count_the_n
页:
[1]