これは私が持っているものです
my %count_words;
while (<DATA>){
my $line= $_;
chomp $line;
my @words = split (/ /, "$line");
foreach my $word(@words){
$count_words{"$word"}++;
}
}
foreach my $key (%count_words){
print "\"$key\" occurs \"$count_words{$key}\" times\n";
}
__DATA__
we name is something
this is what it does
we food food food food
これは私が得る出力です
"it" occurs "1" times
"1" occurs "" times
"what" occurs "1" times
"1" occurs "" times
"name" occurs "1" times
"1" occurs "" times
"food" occurs "1" times
"1" occurs "" times
"does" occurs "1" times
"1" occurs "" times
"is" occurs "2" times
"2" occurs "" times
"we" occurs "2" times
"2" occurs "" times
"food" occurs "3" times
"3" occurs "" times
"something" occurs "1" times
"1" occurs "" times
"this" occurs "1" times
"1" occurs "" times
私の質問は、本質的に以前に作成されたキーと値のペアの値であるこれらの追加のキーが作成された理由です。
これは私が期待するものです
"it" occurs "1" times
"what" occurs "1" times
"name" occurs "1" times
"food" occurs "1" times
"does" occurs "1" times
"is" occurs "2" times
"we" occurs "2" times
"food" occurs "3" times
"something" occurs "1" times
"this" occurs "1" times
誰かが私の明らかな間違いを訂正してもらえますか?