No it's not your fault.

AnyDBM_File is a thin wrapper over any of NDBM_File, DB_File, GDBM_File, SDBM_File and ODBM_File which are a series of different flavours. What AnyDBM_File does is try to load each one (in the order stated) and uses the first working version. My Perl (5.8.8 on Win 32) uses SDBM_File which does define an EXISTS method so does not choke. It looks like dbmmanage insists on SDBM_File (at least on the Apache 2 Win32 port).

Tied hashes require that a number of methods get defined. If they are not things default back to the code in Tie::Hash which in the case of exists is to choke with the error you note. The only way to fix this properly is to patch the source of whatever *DB_File your system is using and add the missing method. As noted it works fine for me so it has quite probably already been fixed and you just have an old version of *DB_File.

Anyway the quick fix answer is don't use exists. Use defined instead.

unless(defined $DBAPACHE{$name}) {
Presumably the DB_File version you are using does not autovivify (create the hash entry) so it will work fine. If not I'm sure someone will patch it by adding the missing EXISTS tie method to the XS.

To find out which version of *DB_File you are actually using try this simple test code (adjust the file path as required and the test username):

use strict; use Fcntl; use AnyDBM_File (); my $file = "C:/dbase"; # no file extension as dbmmanage chops this of +f our @ISA; my %DB; tie (%DB, "AnyDBM_File", $file, 0666, O_RDWR|O_CREAT ) or die "Can't tie $file: $!"; print "ISA @AnyDBM_File::ISA\n"; #my $user = 'test'; #if (exists $DB{$user}) { # print "$user:$DB{$user} found!\n"; #} untie %DB; __DATA__ SDBM_File test:password found!

In reply to Re^5: Database problem by tachyon-II
in thread Database problem by k0rn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.