Storing Object in DBM Hash

Discussion in 'Perl Misc' started by michael.shnitzer@gmail.com, May 16, 2007.

  1. Guest

    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};
    }
     
    , May 16, 2007
    #1
    1. Advertising

  2. Guest

    On May 16, 2:25 pm, wrote:

    <snip>

    Sorry for the double post.
     
    , May 17, 2007
    #2
    1. Advertising

  3. -berlin.de Guest

    <> 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
     
    -berlin.de, Jun 21, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Topher
    Replies:
    1
    Views:
    1,130
    Gunnar Hjalmarsson
    Jan 21, 2004
  2. rp
    Replies:
    1
    Views:
    538
    red floyd
    Nov 10, 2011
  3. Colvin
    Replies:
    3
    Views:
    169
    Colvin
    Dec 30, 2003
  4. Wes Groleau
    Replies:
    6
    Views:
    135
    Tad McClellan
    Jan 16, 2005
  5. Replies:
    2
    Views:
    142
    Martien verbruggen
    May 17, 2007
Loading...

Share This Page