in reply to Re^2: Using array value (from array ref) as hash key??
in thread Using array value (from array ref) as hash key??

$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.

Replies are listed 'Best First'.
Re^4: Using array value (from array ref) as hash key??
by Haddock (Initiate) on May 28, 2007 at 00:36 UTC

    Thanks for your patience Ikegami, I get it now. (finally) :)

    Thanks for the clarification about @out == 1 is a bug, I got that straight from the perl cookbook as a solution (1.19). But I can see that wantarray would be better.