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($_); };

In reply to Re: A better way of lookup? by Corion
in thread A better way of lookup? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.