in reply to Re: Numeric as hash key returns undef...
in thread Numeric as hash key returns undef...
(to the OP) - hash keys are always regarded as strings - that means you should make sure your numeric keys are represented as exactly the right string. I.e. $hash{1.0} is not the same as $hash{1}*. One way of doing that is to use sprintf. For example, if all your keys have 2 places behind the comma, you can use something like this:
Actually, it is. But $hash{"1.0"} is not the same as $hash{1.0} go figure. :-)my $key = sprintf("%0.2f",$number); my $value = $hash{$key}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Numeric as hash key returns undef...
by Anonymous Monk on Oct 24, 2006 at 21:40 UTC | |
by diotalevi (Canon) on Oct 24, 2006 at 21:46 UTC | |
|
Re^3: Numeric as hash key returns undef...
by journey (Monk) on Oct 25, 2006 at 13:36 UTC |