http://www.perlmonks.org?node_id=401024

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' );