in reply to using references as keys in a hash.
Others have pointed out why this is the way it is and pointed you toward modules that will work around it, but I'd like to point out a simpler, more blindingly obvious solution: Go ahead and use the reference as your key, but also store it as a value (in addition to whatever other values you are storing).
There are two ways to do this, and which one you pick is a matter of style. You can use parallel hashes, with the same key across two or more hashes returning a related set of values, or you can use a nested hash. The latter is easier to make look similar to what you have in your code...
%nestedhash = { $someref => { ref => $someref, val => "STUFF", }, $anotherref => { ref => $anotherref, val => stuff(), }, }
Though the way hashes tend to be used in the real world, you're more likely to end up with something more like this...
while (($ref, $val) = get_pair()) { my %thisrecord = { ref => $ref, val => $val }; $record{$ref} = \%thisrecord; }
Personally, I tend to use parallel hashes, which accomplishes roughly the same thing in a slightly different way, like so...
while (($r, $v) = get_pair()) { $ref{$r}=$r; $val{$r}=$v; }
sub H{$_=shift;while($_){$c=0;while(s/^2//){$c++;}s/^4//;$ v.=(' ','|','_',"\n",'\\','/')[$c]}$v}sub A{$_=shift;while ($_){$d=hex chop;for(1..4){$pl.=($d%2)?4:2;$d>>=1}}$pl}$H= "16f6da116f6db14b4b0906c4f324";print H(A($H)) # -- jonadab
|
|---|