1Tie::RefHash(3pm) Perl Programmers Reference Guide Tie::RefHash(3pm)
2
3
4
6 Tie::RefHash - use references as hash keys
7
9 require 5.004;
10 use Tie::RefHash;
11 tie HASHVARIABLE, 'Tie::RefHash', LIST;
12 tie HASHVARIABLE, 'Tie::RefHash::Nestable', LIST;
13
14 untie HASHVARIABLE;
15
17 This module provides the ability to use references as hash keys if you
18 first "tie" the hash variable to this module. Normally, only the keys
19 of the tied hash itself are preserved as references; to use references
20 as keys in hashes-of-hashes, use Tie::RefHash::Nestable, included as
21 part of Tie::RefHash.
22
23 It is implemented using the standard perl TIEHASH interface. Please
24 see the "tie" entry in perlfunc(1) and perltie(1) for more information.
25
26 The Nestable version works by looking for hash references being stored
27 and converting them to tied hashes so that they too can have references
28 as keys. This will happen without warning whenever you store a
29 reference to one of your own hashes in the tied hash.
30
32 use Tie::RefHash;
33 tie %h, 'Tie::RefHash';
34 $a = [];
35 $b = {};
36 $c = \*main;
37 $d = \"gunk";
38 $e = sub { 'foo' };
39 %h = ($a => 1, $b => 2, $c => 3, $d => 4, $e => 5);
40 $a->[0] = 'foo';
41 $b->{foo} = 'bar';
42 for (keys %h) {
43 print ref($_), "\n";
44 }
45
46 tie %h, 'Tie::RefHash::Nestable';
47 $h{$a}->{$b} = 1;
48 for (keys %h, keys %{$h{$a}}) {
49 print ref($_), "\n";
50 }
51
53 Tie::RefHash fully supports threading using the "CLONE" method.
54
56 Storable hooks are provided for semantically correct serialization and
57 cloning of tied refhashes.
58
60 This version of Tie::RefHash seems to no longer work with 5.004. This
61 has not been throughly investigated. Patches welcome ;-)
62
64 Yuval Kogman <nothingmuch@woobling.org>
65
67 Gurusamy Sarathy gsar@activestate.com
68
69 'Nestable' by Ed Avis ed@membled.com
70
72 perl(1), perlfunc(1), perltie(1)
73
74
75
76perl v5.12.4 2011-06-07 Tie::RefHash(3pm)