{
    "mode": "info",
    "parameter": "Tie::ExtraHash",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/Tie%3A%3AExtraHash/json",
    "generated": "2026-07-05T13:26:45Z",
    "synopsis": "package NewHash;\nrequire Tie::Hash;\n@ISA = qw(Tie::Hash);\nsub DELETE { ... }          # Provides needed method\nsub CLEAR { ... }           # Overrides inherited method\npackage NewStdHash;\nrequire Tie::Hash;\n@ISA = qw(Tie::StdHash);\n# All methods provided by default, define\n# only those needing overrides\n# Accessors access the storage in %{$[0]};\n# TIEHASH should return a reference to the actual storage\nsub DELETE { ... }\npackage NewExtraHash;\nrequire Tie::Hash;\n@ISA = qw(Tie::ExtraHash);\n# All methods provided by default, define\n# only those needing overrides\n# Accessors access the storage in %{$[0][0]};\n# TIEHASH should return an array reference with the first element\n# being the reference to the actual storage\nsub DELETE {\n$[0][1]->('del', $[0][0], $[1]); # Call the report writer\ndelete $[0][0]->{$[1]};           #  $[0]->SUPER::DELETE($[1])\n}\npackage main;\ntie %newhash, 'NewHash';\ntie %newstdhash, 'NewStdHash';\ntie %newextrahash, 'NewExtraHash',\nsub {warn \"Doing \\U$[1]\\E of $[2].\\n\"};",
    "sections": {
        "NAME": {
            "content": "Tie::Hash, Tie::StdHash, Tie::ExtraHash - base class definitions for\ntied hashes\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package NewHash;\nrequire Tie::Hash;\n\n@ISA = qw(Tie::Hash);\n\nsub DELETE { ... }          # Provides needed method\nsub CLEAR { ... }           # Overrides inherited method\n\npackage NewStdHash;\nrequire Tie::Hash;\n\n@ISA = qw(Tie::StdHash);\n\n# All methods provided by default, define\n# only those needing overrides\n# Accessors access the storage in %{$[0]};\n# TIEHASH should return a reference to the actual storage\nsub DELETE { ... }\n\npackage NewExtraHash;\nrequire Tie::Hash;\n\n@ISA = qw(Tie::ExtraHash);\n\n# All methods provided by default, define\n# only those needing overrides\n# Accessors access the storage in %{$[0][0]};\n# TIEHASH should return an array reference with the first element\n# being the reference to the actual storage\nsub DELETE {\n$[0][1]->('del', $[0][0], $[1]); # Call the report writer\ndelete $[0][0]->{$[1]};           #  $[0]->SUPER::DELETE($[1])\n}\n\npackage main;\n\ntie %newhash, 'NewHash';\ntie %newstdhash, 'NewStdHash';\ntie %newextrahash, 'NewExtraHash',\nsub {warn \"Doing \\U$[1]\\E of $[2].\\n\"};\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module provides some skeletal methods for hash-tying classes. See\nperltie for a list of the functions required in order to tie a hash to\na package. The basic Tie::Hash package provides a \"new\" method, as well\nas methods \"TIEHASH\", \"EXISTS\" and \"CLEAR\". The Tie::StdHash and\nTie::ExtraHash packages provide most methods for hashes described in\nperltie (the exceptions are \"UNTIE\" and \"DESTROY\").  They cause tied\nhashes to behave exactly like standard hashes, and allow for selective\noverwriting of methods.  Tie::Hash grandfathers the \"new\" method: it is\nused if \"TIEHASH\" is not defined in the case a class forgets to include\na \"TIEHASH\" method.\n\nFor developers wishing to write their own tied hashes, the required\nmethods are briefly defined below. See the perltie section for more\ndetailed descriptive, as well as example code:\n\nTIEHASH classname, LIST\nThe method invoked by the command \"tie %hash, classname\".\nAssociates a new hash instance with the specified class. \"LIST\"\nwould represent additional arguments (along the lines of\nAnyDBMFile and compatriots) needed to complete the association.\n\nSTORE this, key, value\nStore datum value into key for the tied hash this.\n\nFETCH this, key\nRetrieve the datum in key for the tied hash this.\n\nFIRSTKEY this\nReturn the first key in the hash.\n\nNEXTKEY this, lastkey\nReturn the next key in the hash.\n\nEXISTS this, key\nVerify that key exists with the tied hash this.\n\nThe Tie::Hash implementation is a stub that simply croaks.\n\nDELETE this, key\nDelete the key key from the tied hash this.\n\nCLEAR this\nClear all values from the tied hash this.\n\nSCALAR this\nReturns what evaluating the hash in scalar context yields.\n\nTie::Hash does not implement this method (but Tie::StdHash and\nTie::ExtraHash do).\n",
            "subsections": []
        },
        "Inheriting from Tie::StdHash": {
            "content": "The accessor methods assume that the actual storage for the data in the\ntied hash is in the hash referenced by \"tied(%tiedhash)\".  Thus\noverwritten \"TIEHASH\" method should return a hash reference, and the\nremaining methods should operate on the hash referenced by the first\nargument:\n\npackage ReportHash;\nour @ISA = 'Tie::StdHash';\n\nsub TIEHASH  {\nmy $storage = bless {}, shift;\nwarn \"New ReportHash created, stored in $storage.\\n\";\n$storage\n}\nsub STORE    {\nwarn \"Storing data with key $[1] at $[0].\\n\";\n$[0]{$[1]} = $[2]\n}\n",
            "subsections": []
        },
        "Inheriting from Tie::ExtraHash": {
            "content": "The accessor methods assume that the actual storage for the data in the\ntied hash is in the hash referenced by \"(tied(%tiedhash))->[0]\".  Thus\noverwritten \"TIEHASH\" method should return an array reference with the\nfirst element being a hash reference, and the remaining methods should\noperate on the hash \"%{ $[0]->[0] }\":\n\npackage ReportHash;\nour @ISA = 'Tie::ExtraHash';\n\nsub TIEHASH  {\nmy $class = shift;\nmy $storage = bless [{}, @], $class;\nwarn \"New ReportHash created, stored in $storage.\\n\";\n$storage;\n}\nsub STORE    {\nwarn \"Storing data with key $[1] at $[0].\\n\";\n$[0][0]{$[1]} = $[2]\n}\n\nThe default \"TIEHASH\" method stores \"extra\" arguments to tie() starting\nfrom offset 1 in the array referenced by \"tied(%tiedhash)\"; this is the\nsame storage algorithm as in TIEHASH subroutine above.  Hence, a\ntypical package inheriting from Tie::ExtraHash does not need to\noverwrite this method.\n\n\"SCALAR\", \"UNTIE\" and \"DESTROY\"\nThe methods \"UNTIE\" and \"DESTROY\" are not defined in Tie::Hash,\nTie::StdHash, or Tie::ExtraHash.  Tied hashes do not require presence\nof these methods, but if defined, the methods will be called in proper\ntime, see perltie.\n\n\"SCALAR\" is only defined in Tie::StdHash and Tie::ExtraHash.\n\nIf needed, these methods should be defined by the package inheriting\nfrom Tie::Hash, Tie::StdHash, or Tie::ExtraHash. See \"SCALAR\" in\nperltie to find out what happens when \"SCALAR\" does not exist.\n",
            "subsections": []
        },
        "MORE INFORMATION": {
            "content": "The packages relating to various DBM-related implementations (DBFile,\nNDBMFile, etc.) show examples of general tied hashes, as does the\nConfig module. While these do not utilize Tie::Hash, they serve as good\nworking examples.\n\nperl v5.34.0                      2026-06-23                  Tie::Hash(3perl)",
            "subsections": []
        }
    },
    "summary": "Tie::Hash, Tie::StdHash, Tie::ExtraHash - base class definitions for tied hashes",
    "flags": [],
    "examples": [],
    "see_also": []
}