Created
April 12, 2013 04:50
-
-
Save yinyanghu/5369481 to your computer and use it in GitHub Desktop.
Chinese Word Counter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
my $s; | |
my $x; | |
my $y; | |
my $ncword = 0; | |
my $cword = 0; | |
while (<>) { | |
$s = $_; | |
$s =~ s/\s//g; | |
$x = () = $s =~ /[\x00-\x7f]+?/g; | |
$y = () = $s =~ /[^\x00-\x7f]+?/g; | |
$ncword += $x; | |
$cword += $y; | |
} | |
$cword /= 3; | |
print "\n字数统计\n"; | |
print "\t非中文(不含空格):\t$ncword\n"; | |
print "\t中文:\t\t\t$cword\n"; | |
$s = $ncword + $cword; | |
print "\t共计:\t\t\t$s\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment