Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^3: decimal numbers as hash keys

by kennethk (Abbot)
on Jun 26, 2013 at 18:11 UTC ( #1040824=note: print w/replies, xml ) Need Help??

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

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040824]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2016-09-28 05:54 GMT
Find Nodes?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:

    Results (520 votes). Check out past polls.