tomazos has asked for the wisdom of the Perl Monks concerning the following question:

I have successfully created a DBM database using dbmopen/dbmclose and a tied hash on my unix box.

I am now trying to determine how to lock the database so I can have multiple programs accessing it.

From readings in the Perl Cookbook I have determined that the method for doing this is dependant on which DBM implementation is being used on my server.

My question is: How do I determine which DBM implementation my server is using?

Replies are listed 'Best First'.
Re: Which DBM implementation?
by arturo (Vicar) on Jun 12, 2001 at 16:52 UTC

    What DBM are you use ing?

    • DB_File => Berkeley DB
    • GDBM_File => GNU DB
    • SDBM_File => err ... the standard DBM? ( comes w/ Perl )

    In any case, read perldoc [name of DBM you're using] to get the skinny on locking.

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
Re: Which DBM implementation?
by clintp (Curate) on Jun 12, 2001 at 18:05 UTC
    If you can log in to the server, write a short program like:
    dbmopen(%FOO, "hlag", 0666) || die;
    And then run it with the debugger. Step THROUGH the dbmopen and you'll see things like:
    4: our @ISA = qw(NDBM_File DB_File GDBM_File SDBM_File ODBM_File) + unless @ISA; nyDBM_File::(/usr/local/lib/perl5/5.6.0/AnyDBM_File.pm:6): 6: my $mod; nyDBM_File::(/usr/local/lib/perl5/5.6.0/AnyDBM_File.pm:7): 7: for $mod (@ISA) { nyDBM_File::(/usr/local/lib/perl5/5.6.0/AnyDBM_File.pm:8): 8: if (eval "require $mod") {
    AnyDBM is going to step through that @ISA array to find which database is available. The one where the eval works, is the one that you're using.

    There are more hackish ways of doing this like looking at %INC after the dbmopen to see what got brought in successfully.

      I am not calling use, I am just going straight in with dbmopen. The code is:
      $FILENAME = "/blah/blah/test" dbmopen %HASH, $FILENAME, 0666 or die; foreach $key (sort keys %HASH) { print $key, ' = ', $HASH{$key}, "\n"; } dbmclose %HASH;
      When I step through the above dbmopen with perl -d it goes into:

        /usr/lib/perl5/AnyDBM_File

      and that appears to go into:

        /usr/lib/perl5/i386-linux/DB_File.pm

      Am I to understand that this means that it is using the Berkeley DB implementation?

      Update: I'm pretty sure I have figured out that the answer to the above question is yes. Thanks all.