perl的初学者,perl中哈希学的有些混乱,能否就下题给我讲讲哈希?
#!/usr/bin/perlusestrict;my(@words,%count,$word);chomp(@words=<STDIN>);foreach$word(@...
#!/usr/bin/perl
use strict;
my (@words, %count, $word);
chomp(@words = <STDIN>);
foreach $word (@words){
$count{$word}+=1;
print"$count{$word}\n";
}
foreach $word (keys %count){ #或者使用sort keys %count 按顺序输出
print "$word was seen $count{$word} times \n";
} 展开
use strict;
my (@words, %count, $word);
chomp(@words = <STDIN>);
foreach $word (@words){
$count{$word}+=1;
print"$count{$word}\n";
}
foreach $word (keys %count){ #或者使用sort keys %count 按顺序输出
print "$word was seen $count{$word} times \n";
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询