perl faq 学习之统计文件行数

xiaoxiao2026-01-02  5

目的:统计指定文件的行数。 $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]
转载请注明原文地址: https://www.6miu.com/read-5041928.html

最新回复(0)