ODBM_File(3pm)
π ODBM_File π
okay bestie, gather round, because this one is a Perl Programmers Reference Guide classic: ODBM_File β your tied access to odbm files, and she is serving persistence realness. π¦
β¨ NAME β¨
ODBM_File β tied access to odbm files. literally the whole vibe, that's it, that's the name. π
πΈ SYNOPSIS πΈ
here's the whole thing in action, no notes:
use Fcntl; # For O_RDWR, O_CREAT, etc.
use ODBM_File;
tie(%h, 'ODBM_File', 'filename.dbmx', O_RDWR|O_CREAT, 0640)
or die "Couldn't tie ODBM file 'filename.dbmx': $!; aborting";
# Now read and change the hash
$h{newkey} = newvalue;
print $h{oldkey};
...
untie %h;
like. the hash is a hash. and also a file. and also a hash. main character energy fr fr. π
π DESCRIPTION π
ODBM_File establishes a connection between a Perl hash variable and a file in ODBM_File format;. you can manipulate the data in the file just as if it were in a Perl hash, but when your program exits, the data will remain in the file, to be used the next time your program runs. it's giving β¨persistenceβ¨.
use ODBM_File with the Perl built-in tie function to establish the connection between the variable and the file. the arguments to tie should be:
- the hash variable you want to tie. π
- the string
ODBM_File. (this tells Perl to use theODBM_Filepackage to perform the functions of the hash.) - the name of the file you want to tie to the hash. π
- flags. use one of:
O_RDONLYβ read-only access to the data in the file. look but don't touch, bestie πO_WRONLYβ write-only access to the data in the file.O_RDWRβ both read and write access. the full experience, we love her π
if you want to create the file if it does not exist, add O_CREAT to any of these, as in the example. if you omit O_CREAT and the file does not already exist, the tie call will fail. no file, no vibe. π
- the default permissions to use if a new file is created. the actual permissions will be modified by the user's umask, so you should probably use
0666here. (see "umask" in perlfunc.)
π©Ί DIAGNOSTICS π©Ί
on failure, the tie call returns an undefined value and probably sets $! to contain the reason the file could not be tied. she's not ghosting you, she's telling you exactly what went wrong, read the $!. π«Ά
"odbm store returned -1, errno 22, key "..." at ..."
this warning is emitted when you try to store a key or a value that is too long. it means that the change was not recorded in the database. see BUGS AND WARNINGS below. (spoiler: it's the 1008 bytes thing. iykyk. π )
π SECURITY AND PORTABILITY π
do not accept ODBM files from untrusted sources. like, genuinely. this is not a drill, this is the whole paragraph. π¨
on modern Linux systems these are typically GDBM files, which are not portable across platforms. so don't be out here copying them around like they're a cute lil screenshot. β¨
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 old dbm 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. so... unknown. mysterious. not the good kind of mystery. π
a maliciously crafted file might cause perl to crash or even expose a security vulnerability. bestie. bestie no. π
β οΈ BUGS AND WARNINGS β οΈ
there are a number of limits on the size of the data that you can store in the ODBM file. the most important is that the length of a key, plus the length of its associated value, may not exceed 1008 bytes. so if your key and your value are fighting for space, that's on you, and it's also on the 1008 bytes. periodt. π
see "tie" in perlfunc, perldbmfilter, Fcntl
and that's the whole page, bestie!! π this lil legend comes from perl v5.42.3, dated 2026-08-03 β so if you're reading this, hi from the future, hope your hashes are tied and your umask is reasonable. πβ¨π¦ go forth and untie %h responsibly. π
π¦ where this page comes from
- fedora 43: perl-ODBM_File 1.20-524.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- fedora 44: perl-ODBM_File 1.20-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