I'll be glad if someone can enlighten me as to my mistake:
my %mymap;
@mymap{"balloon"} = {1,2,3};
print $mymap{"balloon"}[0] . "\n";
$mymap{'balloon'}
is a hash not an array. The expression {1,2,3}
creates a hash:
{
'1' => 2,
'3' => undef
}
You assigned it to a slice of %mymap
corresponding to the list of keys: ('balloon')
. Since the key list was 1 item and the value list was one item, you did the same thing as
$mymap{'balloon'} = { 1 => 2, 3 => undef };
If you had used strict
and warnings
it would have clued you in to your error. I got:
Scalar value @mymap{"balloon"} better written as $mymap{"balloon"} at - line 3.
Odd number of elements in anonymous hash at - line 3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With