{
    "mode": "perldoc",
    "parameter": "Tie::RefHash",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Tie%3A%3ARefHash/json",
    "generated": "2026-06-03T00:29:23Z",
    "synopsis": "require 5.004;\nuse Tie::RefHash;\ntie HASHVARIABLE, 'Tie::RefHash', LIST;\ntie HASHVARIABLE, 'Tie::RefHash::Nestable', LIST;\nuntie HASHVARIABLE;",
    "sections": {
        "NAME": {
            "content": "Tie::RefHash - Use references as hash keys\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 1.40\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "require 5.004;\nuse Tie::RefHash;\ntie HASHVARIABLE, 'Tie::RefHash', LIST;\ntie HASHVARIABLE, 'Tie::RefHash::Nestable', LIST;\n\nuntie HASHVARIABLE;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module provides the ability to use references as hash keys if you first \"tie\" the hash\nvariable to this module. Normally, only the keys of the tied hash itself are preserved as\nreferences; to use references as keys in hashes-of-hashes, use Tie::RefHash::Nestable, included\nas part of Tie::RefHash.\n\nIt is implemented using the standard perl TIEHASH interface. Please see the \"tie\" entry in",
            "subsections": [
                {
                    "name": "perlfunc",
                    "content": "The Nestable version works by looking for hash references being stored and converting them to\ntied hashes so that they too can have references as keys. This will happen without warning\nwhenever you store a reference to one of your own hashes in the tied hash.\n"
                }
            ]
        },
        "EXAMPLE": {
            "content": "use Tie::RefHash;\ntie %h, 'Tie::RefHash';\n$a = [];\n$b = {};\n$c = \\*main;\n$d = \\\"gunk\";\n$e = sub { 'foo' };\n%h = ($a => 1, $b => 2, $c => 3, $d => 4, $e => 5);\n$a->[0] = 'foo';\n$b->{foo} = 'bar';\nfor (keys %h) {\nprint ref($), \"\\n\";\n}\n\ntie %h, 'Tie::RefHash::Nestable';\n$h{$a}->{$b} = 1;\nfor (keys %h, keys %{$h{$a}}) {\nprint ref($), \"\\n\";\n}\n",
            "subsections": []
        },
        "THREAD SUPPORT": {
            "content": "Tie::RefHash fully supports threading using the \"CLONE\" method.\n",
            "subsections": []
        },
        "STORABLE SUPPORT": {
            "content": "Storable hooks are provided for semantically correct serialization and cloning of tied\nrefhashes.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "",
            "subsections": [
                {
                    "name": "perl",
                    "content": ""
                }
            ]
        },
        "SUPPORT": {
            "content": "Bugs may be submitted through the RT bug tracker\n<https://rt.cpan.org/Public/Dist/Display.html?Name=Tie-RefHash> (or bug-Tie-RefHash@rt.cpan.org\n<mailto:bug-Tie-RefHash@rt.cpan.org>).\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Gurusamy Sarathy <gsar@activestate.com>\n\nTie::RefHash::Nestable by Ed Avis <ed@membled.com>\n",
            "subsections": []
        },
        "CONTRIBUTORS": {
            "content": "*   Yuval Kogman <nothingmuch@woobling.org>\n\n*   Karen Etheridge <ether@cpan.org>\n\n*   Florian Ragwitz <rafl@debian.org>\n\n*   Jerry D. Hedden <jdhedden@cpan.org>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENCE": {
            "content": "This software is copyright (c) 2006 by יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
            "subsections": []
        }
    },
    "summary": "Tie::RefHash - Use references as hash keys",
    "flags": [],
    "examples": [
        "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\";"
    ],
    "see_also": []
}