--- In perl-beginner%40yahoogroups.com">perl-beginner
yahoogroups.com, aditi gupta <aditi9783
...> wrote:
>
> I was wondering whether it is possible to have arrays as hash keys.
For example:
>
> %hash = { ["a", "b"] => ["c", "d"] };
Hashes (and arrays) can only hold scalars, that is, a string, a number
or a reference. So in your example the hash will look like (if dumped
with Data:
umper):
$VAR1 = {
'ARRAY(0x804e15c)' => [
'c',
'd'
]
};
Of course, that number is quite random, and, more importantly, if you
tried to overwrite it like this:
$hash{["a", "b"]} = 'something else';
you would actually insert one more pair with some other random
reference instead:
$VAR1 = {
'ARRAY(0x804e15c)' => [
'c',
'd'
],
'ARRAY(0x809add4)' => 'something else'
};
/sandy http://myperlquiz.com/
.