這是我哈希有額外的按鍵
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
可有人請糾正我的明顯錯誤?
D'oh!十秒鐘太慢....:P – 2012-12-10 16:37:33
那麼誰會想到:)謝謝 – Amey