{
    "mode": "perldoc",
    "parameter": "Tie::IxHash",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Tie%3A%3AIxHash/json",
    "generated": "2026-06-10T16:55:17Z",
    "synopsis": "# simple usage\nuse Tie::IxHash;\ntie HASHVARIABLE, 'Tie::IxHash' [, LIST];\n# OO interface with more powerful features\nuse Tie::IxHash;\nTIEOBJECT = Tie::IxHash->new( [LIST] );\nTIEOBJECT->Splice( OFFSET [, LENGTH [, LIST]] );\nTIEOBJECT->Push( LIST );\nTIEOBJECT->Pop;\nTIEOBJECT->Shift;\nTIEOBJECT->Unshift( LIST );\nTIEOBJECT->Keys( [LIST] );\nTIEOBJECT->Values( [LIST] );\nTIEOBJECT->Indices( LIST );\nTIEOBJECT->Delete( [LIST] );\nTIEOBJECT->Replace( OFFSET, VALUE, [KEY] );\nTIEOBJECT->Reorder( LIST );\nTIEOBJECT->SortByKey;\nTIEOBJECT->SortByValue;\nTIEOBJECT->Length;",
    "sections": {
        "NAME": {
            "content": "Tie::IxHash - ordered associative arrays for Perl\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "# simple usage\nuse Tie::IxHash;\ntie HASHVARIABLE, 'Tie::IxHash' [, LIST];\n\n# OO interface with more powerful features\nuse Tie::IxHash;\nTIEOBJECT = Tie::IxHash->new( [LIST] );\nTIEOBJECT->Splice( OFFSET [, LENGTH [, LIST]] );\nTIEOBJECT->Push( LIST );\nTIEOBJECT->Pop;\nTIEOBJECT->Shift;\nTIEOBJECT->Unshift( LIST );\nTIEOBJECT->Keys( [LIST] );\nTIEOBJECT->Values( [LIST] );\nTIEOBJECT->Indices( LIST );\nTIEOBJECT->Delete( [LIST] );\nTIEOBJECT->Replace( OFFSET, VALUE, [KEY] );\nTIEOBJECT->Reorder( LIST );\nTIEOBJECT->SortByKey;\nTIEOBJECT->SortByValue;\nTIEOBJECT->Length;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This Perl module implements Perl hashes that preserve the order in which the hash elements were\nadded. The order is not affected when values corresponding to existing keys in the IxHash are\nchanged. The elements can also be set to any arbitrary supplied order. The familiar perl array\noperations can also be performed on the IxHash.\n\nStandard \"TIEHASH\" Interface\nThe standard \"TIEHASH\" mechanism is available. This interface is recommended for simple uses,\nsince the usage is exactly the same as regular Perl hashes after the \"tie\" is declared.\n",
            "subsections": [
                {
                    "name": "Object Interface",
                    "content": "This module also provides an extended object-oriented interface that can be used for more\npowerful operations with the IxHash. The following methods are available:\n\nFETCH, STORE, DELETE, EXISTS\nThese standard \"TIEHASH\" methods mandated by Perl can be used directly. See the \"tie\"\nentry in perlfunc(1) for details.\n\nPush, Pop, Shift, Unshift, Splice\nThese additional methods resembling Perl functions are available for operating on\nkey-value pairs in the IxHash. The behavior is the same as the corresponding perl\nfunctions, except when a supplied hash key already exists in the hash. In that case, the\nexisting value is updated but its order is not affected. To unconditionally alter the\norder of a supplied key-value pair, first \"DELETE\" the IxHash element.\n\nKeys    Returns an array of IxHash element keys corresponding to the list of supplied indices.\nReturns an array of all the keys if called without arguments. Note the return value is\nmostly only useful when used in a list context (since perl will convert it to the number\nof elements in the array when used in a scalar context, and that may not be very\nuseful).\n\nIf a single argument is given, returns the single key corresponding to the index. This\nis usable in either scalar or list context.\n\nValues  Returns an array of IxHash element values corresponding to the list of supplied indices.\nReturns an array of all the values if called without arguments. Note the return value is\nmostly only useful when used in a list context (since perl will convert it to the number\nof elements in the array when used in a scalar context, and that may not be very\nuseful).\n\nIf a single argument is given, returns the single value corresponding to the index. This\nis usable in either scalar or list context.\n\nIndices Returns an array of indices corresponding to the supplied list of keys. Note the return\nvalue is mostly only useful when used in a list context (since perl will convert it to\nthe number of elements in the array when used in a scalar context, and that may not be\nvery useful).\n\nIf a single argument is given, returns the single index corresponding to the key. This\nis usable in either scalar or list context.\n\nDelete  Removes elements with the supplied keys from the IxHash.\n\nReplace Substitutes the IxHash element at the specified index with the supplied value-key pair.\nIf a key is not supplied, simply substitutes the value at index with the supplied value.\nIf an element with the supplied key already exists, it will be removed from the IxHash\nfirst.\n\nReorder This method can be used to manipulate the internal order of the IxHash elements by\nsupplying a list of keys in the desired order. Note however, that any IxHash elements\nwhose keys are not in the list will be removed from the IxHash.\n\nLength  Returns the number of IxHash elements.\n\nSortByKey\nReorders the IxHash elements by textual comparison of the keys.\n\nSortByValue\nReorders the IxHash elements by textual comparison of the values.\n\nClear   Resets the IxHash to its pristine state: with no elements at all.\n"
                }
            ]
        },
        "EXAMPLE": {
            "content": "use Tie::IxHash;\n\n# simple interface\n$t = tie(%myhash, 'Tie::IxHash', 'a' => 1, 'b' => 2);\n%myhash = (first => 1, second => 2, third => 3);\n$myhash{fourth} = 4;\n@keys = keys %myhash;\n@values = values %myhash;\nprint(\"y\") if exists $myhash{third};\n\n# OO interface\n$t = Tie::IxHash->new(first => 1, second => 2, third => 3);\n$t->Push(fourth => 4); # same as $myhash{'fourth'} = 4;\n($k, $v) = $t->Pop;    # $k is 'fourth', $v is 4\n$t->Unshift(neg => -1, zeroth => 0);\n($k, $v) = $t->Shift;  # $k is 'neg', $v is -1\n@oneandtwo = $t->Splice(1, 2, foo => 100, bar => 101);\n\n@keys = $t->Keys;\n@values = $t->Values;\n@indices = $t->Indices('foo', 'zeroth');\n@itemkeys = $t->Keys(@indices);\n@itemvals = $t->Values(@indices);\n$t->Replace(2, 0.3, 'other');\n$t->Delete('second', 'zeroth');\n$len = $t->Length;     # number of key-value pairs\n\n$t->Reorder(reverse @keys);\n$t->SortByKey;\n$t->SortByValue;\n",
            "subsections": []
        },
        "BUGS": {
            "content": "You cannot specify a negative length to \"Splice\". Negative indexes are OK, though.\n",
            "subsections": []
        },
        "NOTE": {
            "content": "Indexing always begins at 0 (despite the current $[ setting) for all the functions.\n",
            "subsections": []
        },
        "TODO": {
            "content": "Addition of elements with keys that already exist to the end of the IxHash must be controlled by\na switch.\n\nProvide \"TIEARRAY\" interface when it stabilizes in Perl.\n\nRewrite using XSUBs for efficiency.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Gurusamy Sarathy gsar@umich.edu\n\nCopyright (c) 1995 Gurusamy Sarathy. All rights reserved. This program is free software; you can\nredistribute it and/or modify it under the same terms as Perl itself.\n",
            "subsections": []
        },
        "VERSION": {
            "content": "Version 1.23\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "",
            "subsections": [
                {
                    "name": "perl",
                    "content": ""
                }
            ]
        }
    },
    "summary": "Tie::IxHash - ordered associative arrays for Perl",
    "flags": [],
    "examples": [
        "use Tie::IxHash;",
        "# simple interface",
        "$t = tie(%myhash, 'Tie::IxHash', 'a' => 1, 'b' => 2);",
        "%myhash = (first => 1, second => 2, third => 3);",
        "$myhash{fourth} = 4;",
        "@keys = keys %myhash;",
        "@values = values %myhash;",
        "print(\"y\") if exists $myhash{third};",
        "# OO interface",
        "$t = Tie::IxHash->new(first => 1, second => 2, third => 3);",
        "$t->Push(fourth => 4); # same as $myhash{'fourth'} = 4;",
        "($k, $v) = $t->Pop;    # $k is 'fourth', $v is 4",
        "$t->Unshift(neg => -1, zeroth => 0);",
        "($k, $v) = $t->Shift;  # $k is 'neg', $v is -1",
        "@oneandtwo = $t->Splice(1, 2, foo => 100, bar => 101);",
        "@keys = $t->Keys;",
        "@values = $t->Values;",
        "@indices = $t->Indices('foo', 'zeroth');",
        "@itemkeys = $t->Keys(@indices);",
        "@itemvals = $t->Values(@indices);",
        "$t->Replace(2, 0.3, 'other');",
        "$t->Delete('second', 'zeroth');",
        "$len = $t->Length;     # number of key-value pairs",
        "$t->Reorder(reverse @keys);",
        "$t->SortByKey;",
        "$t->SortByValue;"
    ],
    "see_also": []
}