Subject: | Tie::DxHash bug... internal pointer not being reset? |
* Tie::DxHash v0.93 (i assume, just got it today by doing a
Show quoted text
CPAN>install command).
* Perl v5.8.8
* 2.6.9-xenU #2 Wed Nov 10 13:54:13 CST 2004 i686 GNU/Linux (debian
3.0 linux build).
I am trying to use Tie::DxHash inside of <Perl> sections in my
httpd.conf file (apache 2.0.54 with mod_perl 2.0.2). I put together
this simplified sample code (that I've attached) to demonstrate the
issue I'm having with the package.
**HOWEVER** I also tested the attached code in just a simple .pl perl
program, and it also behaves exactly the same way.
Basically, you can see the code has 3 sections in it.
The first one demonstrates using Tie::IxHash. You can see that
ordering is maintained (unlike a regular hash) as expected, but that
duplicate indexes are overwritten, rather than duplicated.
The second section demonstrates the same code with Tie::DxHash
instead. Also, notice I have commented out the call to the "keys"
function in this section. The output is as expected, order is
preserved, and duplicate keys are not overwritten but added to the end.
The third section illustrates the "bug". By simply uncommenting out
the call to the keys function, it causes the rest of the assignment
calls that add key/value pairs to the hash to "fail" (apparently,
though no warning output or errors seem to be given). The result
output then only shows the original contents of the hash before the
call to "keys".
I had some working code doing something similar, with IxHash, but have
run across the need for duplicate keys, so I tried to just switch to
DxHash, and have run into this issue now.
I actually discovered this *not* while using "keys", but using a while
loop with "each", but the behavior is exactly the same. I thought
from what I read online that "keys" function calls should reset an
internal iteration pointer (that "each" is using, for instance), and
so I guessed that perhaps DxHash had some issue with not resetting
after the last call to "each", so I tried to put in the "keys" call,
as a bunch of websites say to do, and still, nothing.
This simplified example in the attached code shows that merely
obtaining the number of keys (with keys in the scalar context) messes
something up with the hash, so that it cannot be added to after that.
In fact, to add to the mix, in the perl only version (not in apache),
i get some additional warning output when I make a call to the "print
Dumper", *then* add some values, *then* "print Dumper" again. The
warning output doesn't occur until that second call to the attempted-
changed hash, and it says "Use of uninitialized value in string eq
at /usr/local/lib/perl5/site_perl/5.8.8/Tie/DxHash.pm line 69."
So, my guess from all of this is that there is some bug with how
Tie::DxHash is handling and resetting the internal iterator/pointer.
Can you confirm such? Fix or workaround?
Subject: | tie_dxhash_bug_demo.txt |
<Perl>
use Data::Dumper;
use Tie::DxHash;
use Tie::IxHash;
#################################################################################
my %ix_temp;
tie(%ix_temp, Tie::IxHash);
$ix_temp{"a"} = '1';
$ix_temp{"b"} = '2';
$ix_temp{"c"} = '3';
my $ix_keys = scalar keys %ix_temp;
$ix_temp{"a"} = 'sss';
$ix_temp{"b"} = 'ttt';
$ix_temp{"f"} = '3';
print Dumper %ix_temp;
# prints out:
# $VAR1 = 'a';
# $VAR2 = 'sss';
# $VAR3 = 'b';
# $VAR4 = 'ttt';
# $VAR5 = 'c';
# $VAR6 = '3';
# $VAR7 = 'f';
# $VAR8 = '3';
#
# correct, expected behavior
#################################################################################
my %dx_temp;
tie(%dx_temp, Tie::DxHash);
$dx_temp{"a"} = '1';
$dx_temp{"b"} = '2';
$dx_temp{"c"} = '3';
#my $dx_keys = scalar keys %dx_temp;
$dx_temp{"a"} = 'sss';
$dx_temp{"b"} = 'ttt';
$dx_temp{"f"} = '3';
print Dumper %dx_temp;
# prints out:
# $VAR1 = 'a';
# $VAR2 = '1';
# $VAR3 = 'b';
# $VAR4 = '2';
# $VAR5 = 'c';
# $VAR6 = '3';
# $VAR7 = 'a';
# $VAR8 = 'sss';
# $VAR9 = 'b';
# $VAR10 = 'ttt';
# $VAR11 = 'f';
# $VAR12 = '3';
#
# correct, expected behavior, notice the "keys" function call is commented out
#################################################################################
my %dx_temp2;
tie(%dx_temp2, Tie::DxHash);
$dx_temp2{"a"} = '1';
$dx_temp2{"b"} = '2';
$dx_temp2{"c"} = '3';
my $dx_keys2 = scalar keys %dx_temp2;
$dx_temp2{"a"} = 'sss';
$dx_temp2{"b"} = 'ttt';
$dx_temp2{"f"} = '3';
print Dumper %dx_temp2;
# prints out:
# $VAR1 = 'a';
# $VAR2 = '1';
# $VAR3 = 'b';
# $VAR4 = '2';
# $VAR5 = 'c';
# $VAR6 = '3';
#
# unexpected behavior/bug. calling "keys" function apparently causes subsequent assignments to the hash to fail.
</Perl>