in reply to Approximate Matching Key

Given the hash, %hash, and target value $value...
pop grep { $_ <= $value } ( sort { $a <=> $b } keys %hash );
Quick comment/update...

The best code to use is going to depend on both the size and the sparseness of your hash. Define M as the maximum hash value that you plan to have, n as the number of hash entries. The "start at X, check hash backwards" method will take O(M/n) assuming a good distribution, while my method above will take O(n)+O(n*log n) ~ O(n*log n). Thus, if you have a dense hash, the count-backwards will be faster, while grep/sort will be faster for a sparse hash. You'll probably want to benchmark both to see which method is best suited for what you need if you are going to be using this call frequently.


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain