$key = @...[...]; <--- Wrong ^ ^ It may work because Perl is "smart", | | but Perl doesn't always guess correctly. +------+ $key = $...[...]; <--- Right ^ ^ | | +------+
A hash key is a scalar, so you need a "$ expression".
# Wrong: print "hope 1 @{$months->[$i]}\n"; print "hope 2 $monthhash{trim(@{$months->[$i]})}\n"; print "hope 2A $monthhash{@{$months->[$i]}}\n"; # Right: print "hope 1 $months->[$i][0]\n"; print "hope 2 $monthhash{trim($months->[$i][0])}\n"; print "hope 2A $monthhash{$months->[$i][0]}\n";
You're assuming an array of one element (@array) is interchangeable with the element ($array[0]). That's not always the case. In fact, you should assume it's not the case.
By the way, @out == 1 is a bug. You should replace @out == 1 with wantarray. You'll get some interesting results when you do.
In reply to Re^3: Using array value (from array ref) as hash key??
by ikegami
in thread Using array value (from array ref) as hash key??
by Haddock
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |