BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:

Having read merlyn's piece on DBM::Deep, it sounded like something that I've wanted for a long time and decided to have a play and wrote the following snippet.

#! perl -slw use strict; use Data::Dumper; use DBM::Deep; unlink './test.dbm'; # my $db = DBM::Deep::new( './test.dbm' ); # gives Can't locate object method "TIEHASH" via # package "./test.dbm" at c:/Perl/site/lib/DBM/Deep.pm line 121 my $db = new DBM::Deep './test.dbm'; $db->{test} = { fred => [ 1 .. 10 ], bill => [ 'a' .. 'z' ] }; print Dumper $db; # The above results in many errors like the following. # Use of uninitialized value in string ne at c:/Perl/site/lib/DBM/Deep +.pm line 704. # Use of uninitialized value in substr at c:/Perl/site/lib/DBM/Deep.pm + line 711. # Use of uninitialized value in substr at c:/Perl/site/lib/DBM/Deep.pm + line 711. # substr outside of string at c:/Perl/site/lib/DBM/Deep.pm line 711. undef $db; $db = new DBM::Deep './test.dbm'; print Dumper $db; # Ditto the above errors.

The first thing I encountered was that the module seems to require the use of indirect object syntax new(), which I tend to use when the constructor takes no arguments, but not when it does.

The second problem was that when I tried to use Data::Dumper to inspect the contents of the hash I created, it causes loads of errors.

Before I send a bug report, am I doing anythng stupid that I haven't spotted? (I tend to be blind to my own errors as some may have noticed:)


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re: DBM::Deep problems
by saskaqueer (Friar) on May 20, 2004 at 04:23 UTC

    Surely you meant DBM::Deep->new( './test.dbm' );. Note the arrow operator, not a double colon :)

    There is info in the docs about autovivification (update: The proper documentation segment). Try doing this instead and see if it works:

    $db->{test} = {}; $db->{test}->{fred} = [ 1 .. 10 ]; $db->{test}->{bill} = [ 'a' .. 'z' ]; # if the above doesn't work either, try the # following ridiculous snippet: $db->{test} = {}; $db->{test}->{fred} = []; push( @{ $db->{test}->{fred} }, $_ ) for ( 1 .. 10 ); $db->{test}->{bill} = []; push( @{ $db->{test}->{bill} }, $_ ) for ( 'a' .. 'z' );

    update: It's your command line switches. 'l', the line ending one is making this happen somehow. I tried mucking around with your script and as soon as the '-l' switch is removed it's all fine. Final working script:

    #!c:/perl/bin/perl -w use strict; use DBM::Deep; use Data::Dumper; unlink './test.dbm'; my $db = DBM::Deep->new( './test.dbm' ); $db->{test} = { fred => [ 1 .. 10 ], bill => [ 'a' .. 'z' ] }; print Dumper $db;
      That was not an example of autovivification and that warning does not apply here.

      Perfect, thanks.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
Re: DBM::Deep problems
by bmann (Priest) on May 20, 2004 at 04:26 UTC
    DBM::Deep::new is not a method call, it is a function call. Changing the "::" to "->" gets rid of the TIEHASH error.

    I downloaded DBM::Deep today, and can't duplicate the other errors. The output of your test script on my box follows:

    A reply falls below the community's threshold of quality. You may see it by logging in.