Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Odd behavior with DBM::Deep

by Nitrox (Chaplain)
on Oct 21, 2004 at 00:28 UTC ( #401024=perlquestion: print w/replies, xml ) Need Help??

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

I've been familiarizing myself with DBM::Deep(v0.94) the last couple of days and have run into some weird behavior. I've read the documentation numerous times and don't see any errors, but again, I'm new to this module and wouldn't be surprised if it's something I'm doing wrong (seeing as the module has been around a couple of years).

The anomaly occurs when I shift an element off a "deep" array. I'm returned the first element as expected but when inspecting the structure after the shift, the first element is still in the array but what was the second element is missing.

Does anyone see where I'm going wrong or is this indeed a bug that should be reported to the author?

Here's a code stub that recreates the issue on my system (ActiveState v5.8.4 on WinXP):

#!/usr/bin/perl -w use strict; use DBM::Deep; use Data::Dumper; my $DBM = DBM::Deep->new("deep.db") or die("Couldn't initialize DB"); $DBM->clear(); $DBM->optimize(); $DBM->{TASK_QUEUE} = {}; $DBM->{TASK_QUEUE}->{DEV} = []; $DBM->{TASK_QUEUE}->{DEV}->push({CMD => "foo1", FILE => "bar1"}); $DBM->{TASK_QUEUE}->{DEV}->push({CMD => "foo2", FILE => "bar2"}); print Dumper(\$DBM); my $task = $DBM->{TASK_QUEUE}->{DEV}->shift(); print Dumper(\$task); print Dumper(\$DBM); __END__
Here is the output from the first Data::Dumper call:
$VAR1 = \bless( { 'TASK_QUEUE' => bless( { 'DEV' => bless( [ bless( { 'FILE' => 'bar1', 'CMD' => 'foo1' }, 'DBM::Deep' ), bless( { 'FILE' => 'bar2', 'CMD' => 'foo2' }, 'DBM::Deep' ) ], 'DBM::Deep' ) }, 'DBM::Deep' ) }, 'DBM::Deep' );
Then a task is shift'ed off the array and a dump shows that we indeed have the first element:
$VAR1 = \bless( { 'FILE' => 'bar1', 'CMD' => 'foo1' }, 'DBM::Deep' );
But the second dump of the deep structure shows that the second element is missing:
$VAR1 = \bless( { 'TASK_QUEUE' => bless( { 'DEV' => bless( [ bless( { 'FILE' => 'bar1', 'CMD' => 'foo1' }, 'DBM::Deep' ) ], 'DBM::Deep' ) }, 'DBM::Deep' ) }, 'DBM::Deep' );

Replies are listed 'Best First'.
Re: Odd behavior with DBM::Deep
by kvale (Monsignor) on Oct 21, 2004 at 00:38 UTC
    Your code works for me:
    ivy 1003% perl dbmdeep.pl $$VAR1 = \bless( { 'TASK_QUEUE' => bless( { 'DEV' => bless( [ bless( { 'FILE' => 'bar1', 'CMD' => 'foo1' }, 'DBM::Deep' ), bless( { 'FILE' => 'bar2', 'CMD' => 'foo2' }, 'DBM::Deep' ) ], 'DBM::Deep' ) }, 'DBM::Deep' ) }, 'DBM::Deep' ); $VAR1 = \bless( { 'FILE' => 'bar1', 'CMD' => 'foo1' }, 'DBM::Deep' ); $VAR1 = \bless( { 'TASK_QUEUE' => bless( { 'DEV' => bless( [ bless( { 'FILE' => 'bar2', 'CMD' => 'foo2' }, 'DBM::Deep' ) ], 'DBM::Deep' ) }, 'DBM::Deep' ) }, 'DBM::Deep' );
    Perl 5.8.0, DBM::Deep 0.94, Linux 2.4.

    -Mark

      Thanks for testing it, and I'm glad to hear that it's not a coding issue!

      Obviously it's an environment issue, so now I just have narrow down if it's an issue with Perl 5.8.4 or specifically with ActiveState's release. Anyone?

      -Nitrox

        Seems to be okay on 5.8.4/AS810 with DBM::Deep v0.94.

        P:\test>test2 $VAR1 = \bless( { 'TASK_QUEUE' => bless( { 'DEV' => bless( [ bless( { 'FILE' => 'bar1', 'CMD' => 'foo1' }, 'DBM::Deep' ), bless( { 'FILE' => 'bar2', 'CMD' => 'foo2' }, 'DBM::Deep' ) ], 'DBM::Deep' ) }, 'DBM::Deep' ) }, 'DBM::Deep' ); $VAR1 = \bless( { 'FILE' => 'bar1', 'CMD' => 'foo1' }, 'DBM::Deep' ); $VAR1 = \bless( { 'TASK_QUEUE' => bless( { 'DEV' => bless( [ bless( { 'FILE' => 'bar2', 'CMD' => 'foo2' }, 'DBM::Deep' ) ], 'DBM::Deep' ) }, 'DBM::Deep' ) }, 'DBM::Deep' );
        P:\test>perl -V Summary of my perl5 (revision 5 version 8 subversion 4) configuration: Platform: osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread [SNIP] Locally applied patches: ActivePerl Build 810 22751 Update to Test.pm 1.25 21540 Fix backward-compatibility issues in if.pm Built under MSWin32 Compiled at Jun 1 2004 11:52:21 @INC: c:/Perl/lib c:/Perl/site/lib . P:\test>perl -MDBM::Deep -e" print $DBM::Deep::VERSION" 0.94

        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
Re: Odd behavior with DBM::Deep
by Nitrox (Chaplain) on Oct 21, 2004 at 01:37 UTC
    Well, now we're getting somewhere. Checkout this oddity:
    $ppm query DBM-deep Querying target 1 (ActivePerl 5.8.4.810) 1. DBM-Deep [0.94] A pure perl multi-level hash/array DBM
    But...
    $perl -MDBM::Deep -e" print $DBM::Deep::VERSION" 0.93
    Furthermore...
    $ppm upgrade DBM-Deep DBM-Deep 0.94: up to date.
    and the gory details...

    ppm> remove DBM-Deep

    ==================== Remove 'DBM-Deep' version 0.94 from ActivePerl 5.8.4.810. ==================== unlink C:\Perl\html\site\lib\DBM\Deep.html unlink C:\Perl\site\lib\DBM\Deep.pm unlink C:\Perl\site\lib\auto\DBM\Deep\.packlist Successfully removed DBM-Deep version 0.94 from ActivePerl 5.8.4.810.
    ppm> q DBM-Deep
    Querying target 1 (ActivePerl 5.8.4.810) No matches for 'DBM-Deep'; see 'help query'.
    ppm> s DBM-Deep
    Searching in Active Repositories 1. DBM-Deep [0.94] A pure perl multi-level hash/array DBM 2. DBM-Deep [0.94] A pure perl multi-level hash/array DBM
    ppm> d 1
    ==================== Package 1: Name: DBM-Deep Version: 0.94 Author: Joseph Huckaby (jhuckaby@cpan.org) Title: DBM-Deep Abstract: A pure perl multi-level hash/array DBM Location: ActiveState PPM2 Repository Available Platforms: 1. MSWin32-x86-multi-thread-5.8 ====================
    ppm> d 2
    ==================== Package 2: Name: DBM-Deep Version: 0.94 Author: Joseph Huckaby (jhuckaby@cpan.org) Title: DBM-Deep Abstract: A pure perl multi-level hash/array DBM Location: ActiveState Package Repository Available Platforms: 1. MSWin32-x86-multi-thread-5.8 ====================
    ppm> i 1
    Package 1: ==================== Install 'DBM-Deep' version 0.94 in ActivePerl 5.8.4.810. ==================== Downloaded 38895 bytes. Extracting 5/5: blib/arch/auto/DBM/Deep/.exists Installing C:\Perl\html\site\lib\DBM\Deep.html Installing C:\Perl\site\lib\DBM\Deep.pm Successfully installed DBM-Deep version 0.94 in ActivePerl 5.8.4.810.
    $perl -MDBM::Deep -e" print $DBM::Deep::VERSION"
    0.93

    The second package listed reports as being v0.93 once installed as well. Time to file a bug with ActiveState.

    -Nitrox

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://401024]
Approved by kvale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2021-09-27 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?