Hash Issue while Porting from Perl 5.6 to Perl 5.8
by Frank Merrow other posts by this author
Aug 21 2007 2:22PM messages near this date
view in the new Beta List Site
[PMX:VIRUS] The huge mteeorite moves to the Earth!
|
OLE Issue while Porting from Perl 5.6 to Perl 5.8
So I have the following code which has been working find under Perl
5.6 for a number of years:
tie my %stateinfo, 'CrunchHash';
foreach my $field (keys %$TransformedStateHash) {
my $alias = $WatcherAliasFromField{$field};
$stateinfo{$alias} = [$TransformedStateHash-> {$field}, undef];
$stateinfo{$field} = [$TransformedStateHash-> {$field}, undef];
}
So what happens here is that "sometimes" $alias comes back as undef
(this is true under both Perl 5.6 and 5.8).
Under Perl 5.6 that is okay . . . because $stateinfo is a tied hash
and the STORE routine checks the "key" and finds it as "undef" and so
it just NOPs the store . . . that is it just does a "return" in the
STORE routine without trying to save anything in the underlying hash.
Under Perl 5.8, it looks like what is happening is that the check for
undef is done by Perl BEFORE calling STORE . . . as a result it
throws a warning which is not desired.
I mean I could fix the code with a simple "if defined($asia)" at the end.
My concerns are:
1. The if-defined solution, while easy might, there might be are
other situations like this, perhaps a lot of them that are also going
to be an issue. I'd rather not go find/touch all of them.
2. It seems to me that Perl needs to check the key INSIDE STORE . . .
not before the call is made. God only know what STORE might do to
"key" before actually inserting it into the underlying hash. So
while my analysis here seem reasonable on the surface, it really
doesn't make sense given the language construct.
3. Since there is no mention of something like this in the Porting
documents, (at least that I could directly related to this), I'm
wondering if I am dealing with the real problem, or something more
subtle in disguise.
Comments welcomed.
Frank
|