{
    "mode": "perldoc",
    "parameter": "SDBM_File",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/SDBM_File/json",
    "generated": "2026-06-14T13:03:56Z",
    "synopsis": "use Fcntl;   # For ORDWR, OCREAT, etc.\nuse SDBMFile;\ntie(%h, 'SDBMFile', 'filename', ORDWR|OCREAT, 0666)\nor die \"Couldn't tie SDBM file 'filename': $!; aborting\";\n# Now read and change the hash\n$h{newkey} = newvalue;\nprint $h{oldkey};\n...\nuntie %h;",
    "sections": {
        "NAME": {
            "content": "SDBMFile - Tied access to sdbm files\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Fcntl;   # For ORDWR, OCREAT, etc.\nuse SDBMFile;\n\ntie(%h, 'SDBMFile', 'filename', ORDWR|OCREAT, 0666)\nor die \"Couldn't tie SDBM file 'filename': $!; aborting\";\n\n# Now read and change the hash\n$h{newkey} = newvalue;\nprint $h{oldkey};\n...\n\nuntie %h;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"SDBMFile\" establishes a connection between a Perl hash variable and a file in SDBMFile\nformat. You can manipulate the data in the file just as if it were in a Perl hash, but when your\nprogram exits, the data will remain in the file, to be used the next time your program runs.\n",
            "subsections": [
                {
                    "name": "Tie",
                    "content": "Use \"SDBMFile\" with the Perl built-in \"tie\" function to establish the connection between the\nvariable and the file.\n\ntie %hash, 'SDBMFile', $basename, $modeflags, $perms;\n\ntie %hash, 'SDBMFile', $dirfile,  $modeflags, $perms, $pagfilename;\n\n$basename is the base filename for the database. The database is two files with \".dir\" and\n\".pag\" extensions appended to $basename,\n\n$basename.dir     (or .sdbmdir on VMS, per DIRFEXT constant)\n$basename.pag\n\nThe two filenames can also be given separately in full as $dirfile and $pagfilename. This suits\nfor two files without \".dir\" and \".pag\" extensions, perhaps for example two files from\nFile::Temp.\n\n$modeflags can be the following constants from the \"Fcntl\" module (in the style of the open(2)\nsystem call),\n\nORDONLY          read-only access\nOWRONLY          write-only access\nORDWR            read and write access\n\nIf you want to create the file if it does not already exist then bitwise-OR (\"|\") \"OCREAT\" too.\nIf you omit \"OCREAT\" and the database does not already exist then the \"tie\" call will fail.\n\nOCREAT           create database if doesn't already exist\n\n$perms is the file permissions bits to use if new database files are created. This parameter is\nmandatory even when not creating a new database. The permissions will be reduced by the user's\numask so the usual value here would be 0666, or if some very private data then 0600. (See\n\"umask\" in perlfunc.)\n"
                }
            ]
        },
        "EXPORTS": {
            "content": "SDBMFile optionally exports the following constants:\n\n*   \"PAGFEXT\" - the extension used for the page file, usually \".pag\".\n\n*   \"DIRFEXT\" - the extension used for the directory file, \".dir\" everywhere but VMS, where it\nis \".sdbmdir\".\n\n*   \"PAIRMAX\" - the maximum size of a stored hash entry, including the length of both the key\nand value.\n\nThese constants can also be used with fully qualified names, eg. \"SDBMFile::PAGFEXT\".\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "On failure, the \"tie\" call returns an undefined value and probably sets $! to contain the reason\nthe file could not be tied.\n\n\"sdbm store returned -1, errno 22, key \"...\" at ...\"\nThis warning is emitted when you try to store a key or a value that is too long. It means that\nthe change was not recorded in the database. See BUGS AND WARNINGS below.\n",
            "subsections": []
        },
        "SECURITY WARNING": {
            "content": "Do not accept SDBM files from untrusted sources!\n\nThe sdbm file format was designed for speed and convenience, not for portability or security. A\nmaliciously crafted file might cause perl to crash or even expose a security vulnerability.\n",
            "subsections": []
        },
        "BUGS AND WARNINGS": {
            "content": "There are a number of limits on the size of the data that you can store in the SDBM file. The\nmost important is that the length of a key, plus the length of its associated value, may not\nexceed 1008 bytes.\n\nSee \"tie\" in perlfunc, perldbmfilter, Fcntl\n",
            "subsections": []
        }
    },
    "summary": "SDBMFile - Tied access to sdbm files",
    "flags": [],
    "examples": [],
    "see_also": []
}