in reply to UPDATE: mapping lists
in thread mapping lists

The values are probably sorted? Oh-oh.

If you aren't guaranteed they are sorted, you can't use a binary search. You'd have to do a linear pass to test if they are really sorted, and sorting them yourself isn't worth it unless you are going to do lots of range checks on the same data.

Here is a simple linear method that requires no side data structures.

use strict; my @F = ( 1, 2, 4, 8, 32..64, 26 ); sub range{ my($lo, $hi) = @_; return grep {$F[$_] >= $lo and $F[$_] <= $hi} 0..$#F; } print join(',', range(25,35)), "\n";
This is basically what thinker and blokhead did except that my grep is on the indices instead of the values of @F.