http://qs1969.pair.com?node_id=70550


in reply to Approximate Matching Key

How about this?
#!/usr/bin/perl -w use strict; my %data = ( 1 => 'foo', 3 => 'bar', 7 => 'baz', 12 => 'fumble' ); print &find_nearest (10, \%data); sub find_nearest($\%) { my $target = shift; my %data = %{shift()}; while (!defined $data{$target}) { $target--; } return $target; }