NDBM_File(3pm)
π NDBM_File π
okay so bestie, this is the manual page for NDBM_File, part of the Perl Programmers Reference Guide β and yes it's a perl module page, don't @ me, we're doing this.
β¨ NAME β¨
NDBM_File β tied access to ndbm files π
β¨ SYNOPSIS β¨
use Fcntl; # For O_RDWR, O_CREAT, etc.
use NDBM_File;
tie(%h, 'NDBM_File', 'filename', O_RDWR|O_CREAT, 0666)
or die "Couldn't tie NDBM file 'filename': $!; aborting";
# Now read and change the hash
$h{newkey} = newvalue;
print $h{oldkey};
...
untie %h;
β¨ DESCRIPTION β¨
So NDBM_File sets up a whole situationship between a Perl hash variable and a file in NDBM_File format. You get to poke at the data in that file like it's just a regular Perl hash β no cap β but the minute your program exits, the data stays in the file, waiting for next time your program runs. It's giving committed. π
You use NDBM_File together with Perl's built-in tie function to make the connection between the variable and the file. The arguments to tie should be:
- The hash variable you want to tie. π«Ά
- The string
NDBM_File. (This is how you tell Perl to use theNDBM_Filepackage to do all the hash functions.) - The name of the file you want to tie to the hash.
- Flags. Use one of these, bestie:
O_RDONLYβ read-only access to the data in the file.O_WRONLYβ write-only access to the data in the file.O_RDWRβ both read and write access. β¨
And if you want the file to get created when it doesn't exist yet, add O_CREAT to any of those three, like the example does. But if you omit O_CREAT and the file doesn't already exist, the tie call will fail. Tragic but true.
- The default permissions to use if a new file gets created. Real talk: the actual permissions get modified by the user's umask, so you should probably use
0666here. (See"umask" in perlfunc.)
β¨ DIAGNOSTICS β¨
When it fails, the tie call returns an undefined value and probably sets $! to hold the reason the file couldn't be tied. π
πΈ "ndbm store returned -1, errno 22, key "..." at ..." πΈ
This warning shows up when you try to store a key or a value that is too long. It means the change was not recorded in the database β like, it just didn't save, periodt. See BUGS AND WARNINGS below. π
π SECURITY AND PORTABILITY π
Do not accept NDBM files from untrusted sources. Like, seriously, don't. π«
On modern Linux systems these are typically GDBM files, which are not portable across platforms. π
The GDBM documentation doesn't imply that files from untrusted sources can be safely used with libgdbm.
Systems that don't use GDBM compatibility for ndbm support will be using a platform specific library, possibly inherited from BSD systems, where it may or may not be safe to use an untrusted file.
A maliciously crafted file might cause perl to crash or even expose a security vulnerability. That's the scary part, bestie, don't skip it.
π BUGS AND WARNINGS π
There are a number of limits on the size of the data you can store in the NDBM file. The most important one: the length of a key, plus the length of its associated value, may not exceed 1008 bytes. That's the whole vibe check. π
See "tie" in perlfunc, perldbmfilter, Fcntl.
and that's the whole page, bestie!! π¦ this was perl v5.42.3, dated 2026-08-03 β NDBM_File(3pm), iconic, no notes, bye πβ¨π
π¦ where this page comes from
- fedora 43: perl-NDBM_File 1.18-524.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- fedora 44: perl-NDBM_File 1.18-525.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms