use strict; use Search::Binary; my $lastIndex; sub reader { my ($handle, $val, $index) = @_; if (!defined $index) { $lastIndex++; } else { $lastIndex = $index; } return ($val <=> $handle->[$lastIndex], $lastIndex); } my @F = ( 1, 2, 4, 8, 16, 32..64 ); sub range{ my($lo, $hi) = @_; my $lo_pos = binary_search(0,$#F,$lo,\&reader,\@F); my $hi_pos = binary_search(0,$#F,$hi,\&reader,\@F); $hi_pos = $#F if ($hi_pos > $#F); return @F[$lo_pos..$hi_pos]; } print join(',', range(25,35)), "\n"; print join(',', range(50,75)), "\n";