Tie::RefHash(3pm)
π NAME π
okay bestie, this is Tie::RefHash(3pm) from the Perl Programmers Reference Guide, and it's literally the module for using references as hash keys. main character energy, no cap. π
Tie::RefHash β use references as hash keys β¨
π VERSION π
version 1.41 β periodt. π«Ά
π¦ SYNOPSIS π¦
copy this exactly, bestie, no edits, fr fr:
require 5.004;
use Tie::RefHash;
tie HASHVARIABLE, 'Tie::RefHash', LIST;
tie HASHVARIABLE, 'Tie::RefHash::Nestable', LIST;
untie HASHVARIABLE;
πΈ DESCRIPTION πΈ
This module gives you the ability to use references as hash keys β but only if you first tie the hash variable to this module. Normally, only the keys of the tied hash itself are preserved as references; to use references as keys in hashes-of-hashes, use Tie::RefHash::Nestable, included as part of Tie::RefHash. πͺ
It's implemented using the standard perl TIEHASH interface. Please see the "tie" entry in perlfunc(1) and perltie(1) for more information. iykyk.
The Nestable version works by looking for hash references being stored and converting them to tied hashes so that they too can have references as keys. This will happen without warning whenever you store a reference to one of your own hashes in the tied hash. so yeah, surprise feature, not a drill. π
π₯ EXAMPLE π₯
this example is iconic β run it and watch the refs print out:
use Tie::RefHash;
tie %h, 'Tie::RefHash';
$a = [];
$b = {};
$c = \*main;
$d = \"gunk";
$e = sub { 'foo' };
%h = ($a => 1, $b => 2, $c => 3, $d => 4, $e => 5);
$a->[0] = 'foo';
$b->{foo} = 'bar';
for (keys %h) {
print ref($_), "\n";
}
tie %h, 'Tie::RefHash::Nestable';
$h{$a}->{$b} = 1;
for (keys %h, keys %{$h{$a}}) {
print ref($_), "\n";
}
β THREAD SUPPORT β
Tie::RefHash fully supports threading using the CLONE method. slay. π§΅β¨
π STORABLE SUPPORT π
Storable hooks are provided for semantically correct serialization and cloning of tied refhashes. cute and correct. π
π«Ά SEE ALSO π«Ά
π SUPPORT π
Bugs may be submitted through the RT bug tracker at <https://rt.cpan.org/Public/Dist/Display.html?Name=Tie-RefHash> (or bug-Tie-RefHash@rt.cpan.org <mailto:bug-Tie-RefHash@rt.cpan.org>). ππ
π AUTHORS π
Gurusamy Sarathy β <gsar@activestate.com>
Tie::RefHash::Nestable by Ed Avis β <ed@membled.com>
π CONTRIBUTORS π
- Yuval Kogman β
<nothingmuch@woobling.org> - Karen Etheridge β
<ether@cpan.org> - Florian Ragwitz β
<rafl@debian.org> - Lukas Mai β
<lukasmai.403@gmail.com> - Jerry D. Hedden β
<jdhedden@cpan.org> - tusooa β
<tusooa@kazv.moe>
π COPYRIGHT AND LICENCE π
This software is copyright (c) 2006 by ΧΧΧΧ Χ§ΧΧ'ΧΧ (Yuval Kogman) <nothingmuch@woobling.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay bestie, that's the whole page β Tie::RefHash(3pm), perl v5.42.3, dated 2026-11-03. now go tie some refs and slay πβ¨
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms