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>

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