Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Storing Object in DBM Hash

Reply
Thread Tools

Storing Object in DBM Hash

 
 
michael.shnitzer@gmail.com
Guest
Posts: n/a
 
      05-16-2007
Why would the following code work in a regular hash environment but
dereference when using a DBM hash?

"Can't locate object method "docno" via package
"Document=HASH(0x4001d0cc)" (perhaps you forgot to load
"Document=HASH(0x4001d0cc)"?) at read.pl line 6."

#! /usr/bin/perl -w
use strict;

dbmopen(my %hash, "db", 0777);
$hash{mike} = new Document;
print $hash{mike}->docno;

package Document;
sub new
{
my $self = {
document_number => "DOC123",
};
bless $self;
}
sub docno
{
my $self = shift;
return $self->{document_number};
}

 
Reply With Quote
 
 
 
 
michael.shnitzer@gmail.com
Guest
Posts: n/a
 
      05-17-2007
On May 16, 2:25 pm, (E-Mail Removed) wrote:

<snip>

Sorry for the double post.


 
Reply With Quote
 
 
 
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      06-21-2007
<(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Why would the following code work in a regular hash environment but
> dereference when using a DBM hash?


The values of DBM-Tied hashes can only be plain scalars, not references.
After all, references are live addresses in the current program, unfit
to be stored to disk.

CPAN has MLDBM (where ML stands for Multi Level) which deals with
that problem. There may be newer modules for the same purpose.

Anno
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Store Object Class in DBM Hash michael.shnitzer@gmail.com Perl Misc 2 05-17-2007 09:20 PM
Three questions: UTF-8, DBM, hash of lists, ... Wes Groleau Perl Misc 6 01-16-2005 01:45 PM
Sorting entries in a DBM hash by one of the variables Topher Perl 1 01-21-2004 02:28 PM
storing a hash of a hash in a DBM database Colvin Perl Misc 3 12-30-2003 04:38 PM



Advertisments