AnyDBM_File(3pm)
β¨ AnyDBM_File(3pm) β¨
okay bestie, gather round, because this one is literally the glow-up page of the Perl manual set β this is AnyDBM_File, straight out of the Perl Programmers Reference Guide, and it's giving "let me introduce you to the whole DBM friend group" π
πΈ NAME πΈ
AnyDBM_File β provides the framework for multiple DBMs, no cap.
Also doing the intros in this same little page: NDBM_File, DB_File, GDBM_File, SDBM_File, ODBM_File β a.k.a. the various DBM implementations π«Ά
π SYNOPSIS π
use AnyDBM_File;
that's it. that's the whole vibe. iconic, honestly.
π DESCRIPTION π
So here's the tea: this module is a "pure virtual base class" β it has nothing of its own. Like, zero. Nothing. It just sits there so you can inherit from one of the various DBM packages. It's the friend who doesn't drive but always knows a guy π
Its preference order is: ndbm first (for compatibility reasons with Perl 4, nostalgia queen), then Berkeley DB (see DB_File), then GDBM, then SDBM (which is always there β it literally comes with Perl, she's built in), and finally ODBM.
The way this works out is: old programs that used to use NDBM via dbmopen() can still do so, but new ones can reorder @ISA however they like:
BEGIN { @AnyDBM_File::ISA = qw(DB_File GDBM_File NDBM_File) }
use AnyDBM_File;
Having multiple DBM implementations makes it trivial to copy database formats, which is lowkey the best part:
use Fcntl; use NDBM_File; use DB_File;
tie %newhash, 'DB_File', $new_filename, O_CREAT|O_RDWR;
tie %oldhash, 'NDBM_File', $old_filename, 1, 0;
%newhash = %oldhash;
π¦ DBM Comparisons π¦
Here's a partial table of features the different packages offer β consider this the group-chat spreadsheet of who brings what to the function:
odbm ndbm sdbm gdbm bsd-db
---- ---- ---- ---- ------
Linkage comes w/ perl yes yes yes yes yes
Src comes w/ perl no no yes no no
Comes w/ many unix os yes yes[0] no no no
Builds ok on !unix ? ? yes yes ?
Code Size ? ? small big big
Database Size ? ? small big? ok[1]
Speed ? ? slow ok fast
FTPable no no yes yes yes
Easy to build N/A N/A yes yes ok[2]
Size limits 1k 4k 1k[3] none none
Byte-order independent no no no no yes
Licensing restrictions ? ? no yes no
and now the footnotes, because of course there are footnotes π§
- [0] on mixed universe machines, may be in the bsd compat library, which is often shunned. (shunned!! π)
- [1] Can be trimmed if you compile for one access method.
- [2] See
DB_File. Requires symbolic links. - [3] By default, but can be redefined.
π SEE ALSO π
dbm(3), ndbm(3), DB_File(3), perldbmfilter β go read these next bestie, iykyk π
fr fr, don't skip the footnotes and don't skip the table. the table is the whole point. slay π β¨
and that's the page! π written by the Perl fam, from perl v5.42.3, dated 2026-11-03 β go forth and tie your hashes, bestie π
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms