Re: [問題] Perl 用來算所有字出現的次數會不會很 …
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
Perl 近期熱門文章
PTT數位生活區 即時熱門文章