in reply to Setting In-between values in a hash (interpolating)
but it returns null for 3000, because I believe your data is wrong. You imply that the keys should be positive. Try:my %hash = (-5189 => 63, -3213 => 9, -2357 => 3); sub next_key { my ($h,$key) = @_; foreach my $hkey (sort keys %$h) { return $h->{$hkey} if $hkey >= $key; } return; } print next_key(\%hash,3000) . "\n";
my %hash = (5189 => 63, 3213 => 9, 2357 => 3);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Setting In-between values in a hash (interpolating)
by ikegami (Patriarch) on Sep 26, 2008 at 21:13 UTC | |
|
Re^2: Setting In-between values in a hash (interpolating)
by TGI (Parson) on Sep 26, 2008 at 21:45 UTC |