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


in reply to Re^2: decimal numbers as hash keys
in thread decimal numbers as hash keys

The hash key is a string. If you don't do explicit stringification, Perl does it for you. In your case, it does it inconsistently between your construction and access.

You would get identical functionality by trimming trailing zeroes (s/0+$//), but I think that behavior is less obvious, in which case you are setting yourself up for painful maintenance. Another option would be to multiply your factors by 1000, and thus deal with integers instead of decimals.

Update: An improvement on the "trim trailing zeroes" front would be to use the same mechanism that mangled the input in the first place. If you swap to

$jour=$ifac{0+$factor};
you'll invoke the internal Perl conversion to a number and reconvert back to a string for hash access, and hence should hit the correct record.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.