|Perl: the Markov chain saw|
Re: what is anydbm_file?by graff (Chancellor)
|on Apr 01, 2004 at 05:32 UTC||Need Help??|
I share your disappointment with the terseness of the various dbm man pages in perl -- there are some serious gaps there, and it is often not that helpful to read things like "to use this module, you really should have the complete (whatever_dbm C library) manual to refer to". (Guess what I've never been able to find on the university network where I do most of my work...) Hell, just a few more examples for how to open each of the dbm flavors would be nice.
(Update: in the years since I first posted this node, the docs have improved a lot, and easy examples are easy to find.)
In any case, if you intend to be sharing data between the DB_file system and the NDBM/ODBM/SDBM system, you may be up a creek unless at least one of these flavors is common to both systems. As explained in the AnyDBM_File man page (in a rare display of detail), each flavor has its own file storage format and different capacity constraints, so portability of data between two DBM flavors requires that both flavors be available to a given perl installation (on one machine). On top of that, most flavors create data files that are not portable across the big-/little-endian divide -- so even if you had the same DBM module on two machines, the data would not be directly portable if the systems differ in cpu byte-order.
But if you are writing a script such that each installation on a given machine will just be writing/reading data solely on that machine, you can start with something like the following test script, and you shouldn't have to change this to suit particular machines:
Note that the different dbm flavors have different file naming conventions -- some create one file, some create two, some add a standard file extension to the given file name, some do not.
One last issue: the AnyDBM_File man page appears to say that at least one flavor (SDBM_File) is part of the core distribution -- another quick test you should try, just to see what's available (i.e. possible) and what's preferred is simply:
(update: On trying that last little test myself, I may be misunderstanding how @ISA really works in AnyDBM_File. I tried it on a system where I know there's more than one flavor available -- because I've used at least two different ones there in the past -- but only NDBM_File shows up. As a side note, I noticed that using NDBM on macosx creates one file "name.db", while doing the same thing on solaris creates two files, "name.pag" and "name.dir" -- go figure... At least the test script given above worked on both systems without modification; maybe that's all that matters.)