Dr. Mu has asked for the wisdom of the Perl Monks concerning the following question:

Is there a quick way to tell, for a given installation of Perl, what the default DBM version is? In other words, what am I getting if I don't specify "use SDBM_File;" or one of its ilk? My reason for asking is that my hosting service and my home mirror now have two different versions of Perl (5.005 vs. 5.8) and they produce different kinds of files with dbmopen. So I now need to specify a DBM module in my scripts (same on both systems) so both will generate and use the same format that my hosting service uses as a default.

Replies are listed 'Best First'.
Re: WhichDBM_File?
by perrin (Chancellor) on Apr 20, 2004 at 04:37 UTC
    Just look at @AnyDBM_File::ISA. By the way, dbmopen is deprecated in favor of the newer tie() interface.
      Thanks! That's just what I was looking for. Turns out the answer, in my case, is NDBM_File -- on both systems. But they produce files with different filename extensions: 5.8 produces ".pag" and ".dir"; 5.005, ".db". So I'm still not sure there's a way to make any sense of it compatibility-wise...
Re: WhichDBM_File?
by TilRMan (Friar) on Apr 20, 2004 at 04:04 UTC
    $ perl -MSDBM_File -le 'print $SDBM_File::VERSION' 1.03

    This should work for most well-behaved modules, though even good modules can be naughty.

      I guess I phrased the question poorly. I'm not after the version number of any particular DBM module; but rather I need to know which DBM module a particular installation of Perl uses by default if you don't specify one.

        I misunderstood. perrin has it right. Here's what I used on 5.6.1, but I don't have a 5.5 to try it on.

        #!/usr/bin/perl -wl use strict; no strict 'refs'; # Nothing there yet! print "AnyDBM_File::ISA = ", @AnyDBM_File::ISA; dbmopen my %db, "foo", 0777; my $pkg = ref tied %db; print $pkg; my @isa = @{"${pkg}::ISA"}; print @isa; print ${"$isa[0]::VERSION"} __END__ AnyDBM_File::ISA = AnyDBM_File SDBM_File 1.03