in reply to Re^4: Database problem
in thread Database problem
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.
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.unless(defined $DBAPACHE{$name}) {
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Database problem
by k0rn (Acolyte) on Apr 21, 2008 at 19:30 UTC | |
by tachyon-II (Chaplain) on Apr 21, 2008 at 23:09 UTC |