perl中统计单词出现频率的一段代码,大家帮我看看我那里错了?/usr/bin/perl open(MY,"1.txt");while(){while(/fred/){$words {$1}++;} }foreach $_ (keys %words){print "$_$words{$1}\n;"}我的txt文本是fredbarneyfreddinowilmafred
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/14 02:47:26
perl中统计单词出现频率的一段代码,大家帮我看看我那里错了?/usr/bin/perl open(MY,"1.txt");while(){while(/fred/){$words {$1}++;} }foreach $_ (keys %words){print "$_$words{$1}\n;"}我的txt文本是fredbarneyfreddinowilmafred
perl中统计单词出现频率的一段代码,大家帮我看看我那里错了?
/usr/bin/perl
open(MY,"1.txt");while(){
while(/fred/){
$words {$1}++;
} }
foreach $_ (keys %words){
print "$_$words{$1}\n;
"}
我的txt文本是
fred
barney
fred
dino
wilma
fred
perl中统计单词出现频率的一段代码,大家帮我看看我那里错了?/usr/bin/perl open(MY,"1.txt");while(){while(/fred/){$words {$1}++;} }foreach $_ (keys %words){print "$_$words{$1}\n;"}我的txt文本是fredbarneyfreddinowilmafred
#!/usr/bin/perl
use strict;
use warnings;
my %words =();
open(MY,"1.txt")
or die "File problem:$!";
while (){
$words {$1}++ if /(\w+)/ ;
}
foreach (keys %words) {
print $_,"=> ",$words{$_},"\n";
}