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