[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-Modules] [MacPerl] Tie::SubstrHash bug for large hash



I have found what appears to be a bug in the Tie::SubstrHash module 
in MacPerl. I am using MacPerl 5.20r4, patch level 5.004, which is 
listed as the current version for the Macintosh platform. My system 
is a 500 MHz PPC G4 running MacOS 9.0.4, and I've allocated 100 MB of 
RAM for MacPerl.

The following code snip demonstrates the problem very clearly:
#------------------------------
#! /usr/local/bin/perl5

require Tie::SubstrHash;

print "Here we go!\n";
$hashsize = 114_862;		# arbitrary values from my data set
tie %test, "Tie::SubstrHash", 13, 86, $hashsize;

for ($i = 1; $i <= $hashsize; $i++) {
	$key1 = $i + 100_000;		# fix to uniform 6-digit numbers
	$key2 = "abcdefg$key1";
	$test{$key2} = ("abcdefgh" x 10) . "$key1";
}

print scalar(keys %test), "\n";

print %test, "\n";
print $test{"abcdefg207250"}, "\n";
print (keys %test), "\n";
print "\nDone.\n";
#-----------------------------

The entire output generated [eliding a couple of "abcdefgh"'s] is:
Here we go!
1
abcdefg207251abcdefghabcdefghabcdefgh...abcdefghabcdefghabcdefgh207251
abcdefghabcdefghabcdefghabcdefghabcdefgh...abcdefgh207250
abcdefg207251
Done.

Consistently, the tied hash believes that it has only one key, 
"abcdefg207251", and yet if you specify another key, it will retrieve 
the value.

If you remove the "require" and "tie" statements, the program 
performs as expected, using the default hash mechanisms and producing 
an avalanche of output.

I stumbled upon that rather extreme demonstration of the misbehavior 
of a Tie::SubstrHash, but in my real program, a hash with key=6 
value=86 and size=114_862 wound up reporting back about 18% of its 
contents. My real program behaves correctly using the default hash 
mechanisms.

-- 
Linc Madison  *  San Francisco, CA  *  LincPerl@LincMad.com
NO SPAM: California Bus & Prof Code Section 17538.45 applies!

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-modules-request@macperl.org