in reply to Re: reference as hash keys and values
in thread reference as hash keys and values

Good process of testing and deduction. Deductive reasoning like that is one of those qualities present in programmers who are capable of solving problems on their own. I believe logical and deductive reasoning is an attribute that must accompany success as a programmer. Your testing can be summarized well by perlref:

WARNING

You may not (usefully) use a reference as the key to a hash. It will be converted into a string:

$x{ \$a } = $a;

If you try to dereference the key, it won't do a hard dereference, and you won't accomplish what you're attempting. You might want to do something more like

$r = \@a; $x{ $r } = $r;

And then at least you can use the values(), which will be real refs, instead of the keys(), which won't.

The standard Tie::RefHash module provides a convenient workaround to this.

References are passed around as scalars, but keys are indices composed of string values, not full scalar citizens.


Dave