引用混亂雖然看着 http://perl.plover.com/FAQs/references.htmlPerl中使用散列值是陣列
從下面,我真不明白 @{ $table{$state} }
它解釋說,這是哈希表,其中的關鍵是$state
和值數組..所以這基本上是 正常%table
和其值將數組..這是正確的方式來看待這個?
難道還有%{ $table{$state} }
這樣的事嗎?我甚至不知道這是否意味着什麼。
1 while (<>) {
2 chomp;
3 my ($city, $state) = split /, /;
4 push @{$table{$state}}, $city;
5 }
6
7 foreach $state (sort keys %table) {
8 print "$state: ";
9 my @cities = @{$table{$state}};
10 print join ', ', sort @cities;
11 print ".\n";
12 }
請檢查['HoA'](http://perldoc.perl.org/perldsc.html#HASHES-OF-ARRAYS)和['HoH'](http://perldoc.perl.org/perldsc。 html#HASHES-OF-HASHES) –