perl 哈希统计输入的字符串字数
要求:自定义输入一组字符串,例如 aa bb cc aa cc ,那么需要统计出各个字符串出现的次数。
#! /usr/bin/perl
my (@words, %count, $word);
chomp (@words=<STDIN>);
foreach $word (@words) {
$count{$word} += 1;
}
foreach $word (keys %count) {
print "$word was senn $count{$word} times.\n";
}
#! /usr/bin/perl
my (@words, %count, $word);
chomp (@words=<STDIN>);
foreach $word (@words) {
$count{$word} += 1;
}
foreach $word (keys %count) {
print "$word was senn $count{$word} times.\n";
}
none