Re: FAQ 4.69 How can I use a reference as a hash key?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

PerlFAQ Server <comdog@xxxxxxxx> wrote in
news:dlcf95$59b$1@xxxxxxxxxxxxxxxxx:

> 4.69: How can I use a reference as a hash key?
>
> (contributed by brian d foy)
>
> Hash keys are strings, so you can't really use a reference as the
> key. When you try to do that, perl turns the reference into its
> stringified form (for instance, "HASH(0xDEADBEEF)"). From there
> you can't get back the reference from the stringified form, at
> least without doing some extra work on your own. Also remember
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> that hash keys must be unique, but two different variables can
> store the same reference (and those variables can change later).
>
> The Tie::RefHash module, which is distributed with perl, might be
> what you want. It handles that extra work.

What is this "extra work"? I have no clue how to get a reference from
a stringified version of it, other than to manually search the symbol
table, or to write some XS code to cheat (which would probably segfault
and/or memory leak).

- --
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32) - WinPT 0.7.96rc1

iD8DBQFDed33Y96i4h5M0egRAgNpAKCmnwDj1jfu/bOeT0iEAL7XwHe9QgCffuwH
qmVb0nc/IC6Q48SnXxYUdEA=
=iTmB
-----END PGP SIGNATURE-----
.



Relevant Pages