APM: Interesting hash side effect

Brian Michalk michalk at awpi.com
Thu Jan 9 12:45:41 CST 2003


I have had a nagging bug that I finally figured out.
I found that in some cases checking to see if a hash element is defined will
add to the hash.
The following line:
    103     if (defined $self->{keys}{cfg}{$varname}{ref_sub}) {
will add the hash element, $self->{keys}{cfg}{$varname}.  I had to change my
code to the following in order to get it to work correctly.

    102   if (defined $self->{keys}{cfg}{$varname}) {
    103     if (defined $self->{keys}{cfg}{$varname}{ref_sub}) {
    104       return $self->{keys}{cfg}{$varname}{ref_sub};
    105     }
    106   } else {
    107     return undef;
    108   }

I hope this helps anyone else who cares.




More information about the Austin mailing list