Link to home
Start Free TrialLog in
Avatar of moan
moan

asked on

Problem with tie and GDBM

I need to use gdbm databases with Perl but get the error:

"Can't locate object method "TIEHASH" via package "GDBM_FILE" " at
my_first_db.pl line 5."


when using this code:


#! /bin/perl -w
use GDBM_File;
use POSIX;
use Fcntl;
tie(%db, "GDBM_FILE", "my_db", &GDBM_WRCREAT, 0644);


Is it a bug in Perl5.003, or is there a workaround?

I am using Perl5.003 with the gdbm-1.7.3 library statically linked, both
compiled with gcc-2.7.2.2 on a Sun ULTRA running Solaris2.5.
Avatar of mkornell
mkornell

try:

tie(%db, GDBM_File, "my_db", &GDBM_WRCREAT, 0644);

i.e. change "GDBM_FILE" to "GDBM_File".  You also don't need the quotes.
       
ASKER CERTIFIED SOLUTION
Avatar of mkornell
mkornell

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of moan

ASKER

mkornell's answer solved my problem.
The code I tried was directly copied/pasted from an online manual
that had the syntax wrong!