作者littleshan (我要加入剑道社!)
看板perl
标题Re: [问题] Perl 用来算所有字出现的次数会不会很 …
时间Thu Apr 8 15:34:19 2004
perl当然更快 像这样...
perl -ne 's/(\w+)/$w{lc($1)}++/eg; END{print $w{$_}," $_\n" for (keys %w)}'
会从STDIN读资料 输出格式就像你写的那样
※ 引述《asyhuang (Yes, Taiwan)》之铭言:
: 我想试看看用perl做这个问题...
: 是不是 mix shell script 或用其它写会比较快? C/C++当然可以做到,
: 但只用 perl 可以快一点吗?
: produce a count of all the different "words" in a text file.
: Use any definition of word that makes logical sense or makes your job easy.
: The output might look like this:
: 17 a
: 14 the
: 9 of
: 9 in
: 8 com
: 7 you
: 7 that
: 7 mercedsystems
: 6 to
: ...
: For this input file, the word "a" occurred 17 times, "the" 14 times,
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.30.82