Perlのハッシュキーは文字列として保持されます。
リファレンスをキーにしてもそこからデリファレンスはできないことがわかります。
$ref = \"abc"; $hash{$ref} = 123; $key = (keys %hash)[0]; print "$ref is the reference of '$$ref'\n"; print "$key is the reference of '$$key'\n";
出力
SCALAR(0x801734) is the reference of 'abc' SCALAR(0x801734) is the reference of ''
Rubyのハッシュキーは任意のオブジェクトです。
キーになっても何も変わりません。
hash = { "str" => "v1", 123 => "v2", [1, 2, 3] => "v3", {1=>1, 2=>2, 3=>3} => "v4" } hash.keys.each{|k| p [k,k.class]}
出力
[[1, 2, 3], Array] [123, Fixnum] [{1=>1, 2=>2, 3=>3}, Hash] ["str", String]
いろいろ応用が考えられて非常に面白いと思います。
(ただこれが問題になるときもあります。)