{
    "mode": "perldoc",
    "parameter": "NDBM_File",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/NDBM_File/json",
    "generated": "2026-06-15T14:25:42Z",
    "synopsis": "use Fcntl;   # For ORDWR, OCREAT, etc.\nuse NDBMFile;\ntie(%h, 'NDBMFile', 'filename', ORDWR|OCREAT, 0666)\nor die \"Couldn't tie NDBM file 'filename': $!; aborting\";\n# Now read and change the hash\n$h{newkey} = newvalue;\nprint $h{oldkey};\n...\nuntie %h;",
    "sections": {
        "NAME": {
            "content": "NDBMFile - Tied access to ndbm files\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Fcntl;   # For ORDWR, OCREAT, etc.\nuse NDBMFile;\n\ntie(%h, 'NDBMFile', 'filename', ORDWR|OCREAT, 0666)\nor die \"Couldn't tie NDBM 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": "\"NDBMFile\" establishes a connection between a Perl hash variable and a file in NDBMFile\nformat;. You can manipulate the data in the file just as if it were in a Perl hash, but when\nyour program exits, the data will remain in the file, to be used the next time your program\nruns.\n\nUse \"NDBMFile\" with the Perl built-in \"tie\" function to establish the connection between the\nvariable and the file. The arguments to \"tie\" should be:\n\n1.  The hash variable you want to tie.\n\n2.  The string \"NDBMFile\". (Ths tells Perl to use the \"NDBMFile\" package to perform the\nfunctions of the hash.)\n\n3.  The name of the file you want to tie to the hash.\n\n4.  Flags. Use one of:\n\n\"ORDONLY\"\nRead-only access to the data in the file.\n\n\"OWRONLY\"\nWrite-only access to the data in the file.\n\n\"ORDWR\"\nBoth read and write access.\n\nIf you want to create the file if it does not exist, add \"OCREAT\" to any of these, as in\nthe example. If you omit \"OCREAT\" and the file does not already exist, the \"tie\" call will\nfail.\n\n5.  The default permissions to use if a new file is created. The actual permissions will be\nmodified by the user's umask, so you should probably use 0666 here. (See \"umask\" in\nperlfunc.)\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\"ndbm 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 AND PORTABILITY": {
            "content": "Do not accept NDBM files from untrusted sources.\n\nOn modern Linux systems these are typically GDBM files, which are not portable across platforms.\n\nThe GDBM documentation doesn't imply that files from untrusted sources can be safely used with\n\"libgdbm\".\n\nSystems that don't use GDBM compatibilty for ndbm support will be using a platform specific\nlibrary, possibly inherited from BSD systems, where it may or may not be safe to use an\nuntrusted file.\n\nA maliciously 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 NDBM 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": "NDBMFile - Tied access to ndbm files",
    "flags": [],
    "examples": [],
    "see_also": []
}