当前位置: 代码迷 >> CGI >> perl 比一比哪位高手更懒,调查英文单词频率
  详细解决方案

perl 比一比哪位高手更懒,调查英文单词频率

热度:791   发布时间:2012-02-13 17:20:26.0
perl 比一比谁更懒,调查英文单词频率
从STDIN读取sample.txt 。调查单词出现的频率。以出现频率多的顺序排列单词。输出:单词 频率数 (换行)
英语单词不分大小写,输出的时候,以小写字母表示

写出这个程序不难,有兴趣的朋友可以试试以最短的字节写出这个程序。挑战一下80字节?




eg:
sample.txt

The Godhead
It is generally agreed that there are three persons in the Divine Being. Jesus speaks of both the Father and the Holy Spirit. This truth is much more clearly presented in the New Testament than it is in the Old.In Genesis 1:1-3 it is evident that the Godhead was active in the creative process. In John 1:1-3 and Hebrews 1:2,10 it is confirmed that the Word, Jesus, God the Son, had a role in creation.In Genesis 1:1 we read, "In beginning Elohim created the heavens and the earth." Elohim is the Hebrew word for Gods, plural. El is the word for God, singular. Throughout the Old Testament the term Elohim refers to the Godhead. At times it is in construct form, and often with pronominal endings - Elohenu for "our God" - see Deuteronomy 6:4,5.
......
......
......

输出
the 214
in 63
is 60
of 56
and 38
god 33
to 32
......
......
whom 2
pronunciation 2
fullness 2
given 2
work 1
context 1
reading 1
identifying 1
.....
.....
.....



------解决方案--------------------
刚才试了一下,发现输出就要3,40个字节,确实80个字节有点困难。
------解决方案--------------------
思路大致是
open F,"$1";
while(<F>)$_=~/\b(\w)\b/$a{$1}++/eg;
foreach(keys(%a))print "$_:$a{$_}\n";

没有条件调试,仅供参考。