in reply to A better way of lookup?

Maybe instead of a parallel array or arrayreferences, just use a single array with the even offsets being the threshholds and the odd offsets being the clamped values?

use strict; use vars qw(@lookup_values); @lookup_values= (qw( 25000 2500 50000 5000 150000 12500 225000 25000 300000 37500 600000 60000 1200000 120000 3600000 300000 5400000 600000 10800000 900000 21600000 1800000 43200000 3600000 64800000 7200000 129600000 10800000 216000000 21600000 432000000 43200000 864000000 86400000 1728000000 172800000 3024000000 345600000 6048000000 604800000 12096000000 1209600000 31557600000 2629800000 63115200000 5259600000 78894000000 7889400000 157788000000 15778800000 )); sub lookup { my $v= $_[0]; return 31557600000 if $v >= 157788000000; my $i; for( $i= 0; $i <= $#lookup_values-1 && $v >= $lookup_values[$i]; $ +i+=2 ) { # nothing in the loop body #print "$v: $i -> $lookup_values[$i]\n"; }; return $lookup_values[ $i+1 ]; }; for( 10,2500,2501, 157788000000, 157788000001, 78894000000 ) { print sprintf "%d => %d\n", $_, lookup($_); };