in reply to hash key stringification

My question is: how is the expression in $hash{expression} stringified?

Same as everywhere else.

I think that's all the scalar subtypes?

You can force stringification a number of ways, including

"$var"
and
'' . EXPR

The form of the expression I was trying to understand was $href->{$x,$y}

$href->{$x,$y} is rarely used and probably shouldn't be used. I think the only reason it exists is for backwards compatibility with very old Perls. I agree that it should be mentioned in perldata.

Also, how should I, if I were so bold, suggest an improvement to the standard documentation?

perlbug

Replies are listed 'Best First'.
Re^2: hash key stringification
by ig (Vicar) on Apr 07, 2008 at 07:37 UTC
    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.

      Arrays are evaluated in scalar context and the result is converted to a string.

      Not just arrays, but all other expressions.

      Everything else is evaluated as an expression and the result is converted to a string

      "as an expression" is redundant since only expressions can be evaluated, and you forgot to mention scalar context. Perhaps "All other expressions are evaluated in scalar context and their result is converted to a string."