August 1999 | Return to the Perl Hardware Store | Slide #21 |
Hash keys must be strings
What if you want to associate some data with an object instead of with a string?
Use Tie::RefHash. Keys can be arbitrary references.
How does this work? It uses the unstringize trick.
Each hash is actually two hashes: One for keys, one for values.
Both are keyed by the stringized versions of the references
When it wants to figure out the object that it `stored' as a `key', it uses unstringize.
Next | Copyright © 1999 M-J. Dominus |