For starters, perl does not consider e-149 to be a numeric value, so I wll assume you meant 1e-149.
Your question implies that perl would somehow distinguish between arithmetic on hash values and arithmetic on any other scalars, which is not the case. Whatever arithmetic works for $foo and $bar, or $foo[ 0 ] and $bar[ 0 ], works for $foo{ epsilon } and $bar{ epsilon }. In particular
...as expected.% perl -wle '$x = "1e-149"; print $x + "2e-149"' 3e-149 % perl -wle '$hash{ x } = "1e-149"; print $hash{ x } + "2e-149"' 3e-149 % perl -wle '$hash{ x } = "1e-149"; print $hash{ x } + "2e-36"' 2e-36
Last thing is that by default1 perl never interprets + to mean string concatenation. (It has . for that.) This is true even when applied to string operands. In this case the strings get converted to numeric values and added. As shown in the one-liners above, if the strings make sense as numbers, the addition will make sense arithmetically. But even when the operands don't make sense as numbers, perl will be a sport about it and do something:
% perl -wle 'print( "x" + "y" )' Argument "y" isn't numeric in addition (+) at -e line 1. Argument "x" isn't numeric in addition (+) at -e line 1. 0
1I suppose one could overload + for a class to mean concatenation, but this is not default behavior.
the lowliest monk
In reply to Re: Adding hash values together
by tlm
in thread Adding hash values together
by MonkPaul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |