in reply to Re: Perl Number range lookup question
in thread Perl Number range lookup question
Using the precalculated hash would also be slower if the number of lookups isn't substantially larger than the number of precalculated values. If fewer lookups would be done, but the calculation is slower than a hash lookup, the better option would be to do no precalculation and instead do your lookups with
which will calculate the tier for a value the first time it's requested, then return the calculated value from the hash on subsequent requests for that value. (Note that you'll need to use ||= instead of //= if your perl is older than 5.10.)my $tier = $tiers{$n} //= calculate_tier($n);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Perl Number range lookup question
by tobyink (Canon) on Jun 18, 2012 at 17:34 UTC |