假设你的文本是纯英文文字档 ( 不是 unicode )
my @files = @ARGV;
foreach my $file ( @files ) {
open F, $file or die "Can't open $file$/";
my ( $lines, $words, $chars ) ;
my $rawchars = -s $file;
while (my $line =
chomp $line;
my @w = split /[^\w]+/, $line;
$chars += length ( join " ", @w ) ;
$words += @w;
$lines++;
}
print "$file has $lines lines, $words words, $chars chars(true char), $rawchars rawchars(include space, punc, enter)$/";
}
while(<$file>)
{
while(/(\w+)/g)
{
$char+=length($1);
$word++;
}
$line++;
}
写个函数封装下就好了