in reply to Approximate Matching Key

Check to see if the key is in there, otherwise, subtract one at a time until it's found. Cache this, too.
my $nearest_key = nearest(\%hash, $key); { my %nearest; sub nearest { my ($href, $k) = @_; my $low = $k; return $nearest{$k} if exists $nearest{$k}; $low-- until exists $href->{$low}; @nearest{$low .. $k} = ($low) x ($k - $low + 1); return $low; } }


japhy -- Perl and Regex Hacker