Chinaunix首页 | 论坛 | 博客
  • 博客访问: 824331
  • 博文数量: 188
  • 博客积分: 4433
  • 博客等级: 上校
  • 技术积分: 1905
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-14 07:14
个人简介

linux

文章分类

全部博文(188)

文章存档

2016年(6)

2015年(22)

2014年(18)

2013年(5)

2012年(125)

2011年(10)

2010年(2)

分类: IT职场

2012-03-23 10:40:30

#!/usr/bin/perl
use Data::Dumper;
$words;
$/=undef;
open FILE,"/tmp/harry";
chomp($content=);
while ($content){
        if ($content=~/\w+/){
                if (exists $$words{$&}){
                        $$words{$&}++;
                }else{
                        $$words{$&}=1;
                }
                $content=$';
        }else{
                last;
        }
}
close FILE;
@keys = sort { $$words{$b} <=> $$words{$a} } keys %$words;
for (@keys){print "$_ -> $$words{$_}\n"};

用它统计哈利波特第一季,排名前十的高频词:
the -> 3315
to -> 1851
and -> 1812
a -> 1581
Harry -> 1326
of -> 1250
he -> 1209
was -> 1178
in -> 935

只出现过一次的单词有2989个

总共使用了6658个单词


阅读(1178) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~