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