Thanks for the help ikegami.
I am thinking to submit a bug report on the documentation with the following suggestion for an addition:
Hash keys are always strings. Hash subscripts that are not strings
are converted to strings before being used as keys.
A subscript may be a string, simple bareword, list, array
or expression.
A string is used as-is.
A bareword is treated as if it were a quoted string.
A list is joined with the subscript separator C<$;> (see L<perlvar>).
Note that it is not joined with the list separator C<$">, as it would
be if it were being interpolated into a double quoted string.
The following are equivalent:
$hash{'a', 'b', 'c'} = 1;
$hash{join($;, 'a', 'b', 'c')} = 1;
Arrays are evaluated in scalar contex and the result is
converted to a string. Note the difference between an
array and a list, but also that an array can be
interpolated into a list. Alternatively, an array can
be interpolated into a double quoted string. In the
following, 1 and 2 are the same, as are 3 and 4,
as are 5 and 6.
@array = ('a', 'b', 'c');
$hash{@array} = 1; # 1
$hash{'3'} = 1; # 2
$hash{(),@array} = 2; # 3
$hash{join($;, @array)} = 2; # 4
$hash{"@array"} = 3; # 5
$hash{join($",@array)} = 3; # 6
Everything else is evaluated as an expression and the result is
converted to a string. Note that while references can be used
as hash subscripts and are easily converted to string representation
it is not easy to convert the string representation back to a
reference. Note also that array slices are handled differently
than either lists or arrays. They are processed like lists are
in other contexts and yield the last element of the slice.
Any suggestions before it goes to bother those busy people
would be much appreciated. |