![]() |
|
Perl-Sensitive Sunglasses | |
PerlMonks |
Floats with trailing zeros as a hash keyby hardburn (Abbot) |
on May 09, 2003 at 14:43 UTC ( #256884=perlquestion: print w/replies, xml ) | Need Help?? |
hardburn has asked for the wisdom of the Perl Monks concerning the following question: I have various items stored in a hash with the price as the key:
If you must know, the "items" are really subscription orders for a magazine, so there is no chance that two "items" would have the same price. The problem comes when you want to access the hash.
When accessed in numeric context, the '45.20' key drops the trailing zero, but keeps it in string context. The solution I came up with was to have two entries pointing to the same string, one in numeric context and the other in string:
This solution forces you to update two hardcoded hash keys with identicial data. Does anybody see a cleaner solution? ---- Note: All code is untested, unless otherwise stated
Back to
Seekers of Perl Wisdom
|
|