1Tie::RefHash(3) User Contributed Perl Documentation Tie::RefHash(3)
2
3
4
6 Tie::RefHash - Use references as hash keys
7
9 version 1.40
10
12 require 5.004;
13 use Tie::RefHash;
14 tie HASHVARIABLE, 'Tie::RefHash', LIST;
15 tie HASHVARIABLE, 'Tie::RefHash::Nestable', LIST;
16
17 untie HASHVARIABLE;
18
20 This module provides the ability to use references as hash keys if you
21 first "tie" the hash variable to this module. Normally, only the keys
22 of the tied hash itself are preserved as references; to use references
23 as keys in hashes-of-hashes, use Tie::RefHash::Nestable, included as
24 part of Tie::RefHash.
25
26 It is implemented using the standard perl TIEHASH interface. Please
27 see the "tie" entry in perlfunc(1) and perltie(1) for more information.
28
29 The Nestable version works by looking for hash references being stored
30 and converting them to tied hashes so that they too can have references
31 as keys. This will happen without warning whenever you store a
32 reference to one of your own hashes in the tied hash.
33
35 use Tie::RefHash;
36 tie %h, 'Tie::RefHash';
37 $a = [];
38 $b = {};
39 $c = \*main;
40 $d = \"gunk";
41 $e = sub { 'foo' };
42 %h = ($a => 1, $b => 2, $c => 3, $d => 4, $e => 5);
43 $a->[0] = 'foo';
44 $b->{foo} = 'bar';
45 for (keys %h) {
46 print ref($_), "\n";
47 }
48
49 tie %h, 'Tie::RefHash::Nestable';
50 $h{$a}->{$b} = 1;
51 for (keys %h, keys %{$h{$a}}) {
52 print ref($_), "\n";
53 }
54
56 Tie::RefHash fully supports threading using the "CLONE" method.
57
59 Storable hooks are provided for semantically correct serialization and
60 cloning of tied refhashes.
61
63 perl(1), perlfunc(1), perltie(1)
64
66 Bugs may be submitted through the RT bug tracker
67 <https://rt.cpan.org/Public/Dist/Display.html?Name=Tie-RefHash> (or
68 bug-Tie-RefHash@rt.cpan.org <mailto:bug-Tie-RefHash@rt.cpan.org>).
69
71 Gurusamy Sarathy <gsar@activestate.com>
72
73 Tie::RefHash::Nestable by Ed Avis <ed@membled.com>
74
76 • Yuval Kogman <nothingmuch@woobling.org>
77
78 • Karen Etheridge <ether@cpan.org>
79
80 • Florian Ragwitz <rafl@debian.org>
81
82 • Jerry D. Hedden <jdhedden@cpan.org>
83
85 This software is copyright (c) 2006 by יובל קוג'מן (Yuval Kogman)
86 <nothingmuch@woobling.org>.
87
88 This is free software; you can redistribute it and/or modify it under
89 the same terms as the Perl 5 programming language system itself.
90
91
92
93perl v5.32.1 2021-01-27 Tie::RefHash(3)