Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Improve my lookup script

by GlitchMr (Sexton)
on Aug 22, 2012 at 15:14 UTC ( #989073=note: print w/ replies, xml ) Need Help??


in reply to Improve my lookup script

You can use CPAN module, such as List::BinarySearch instead of writing code yourself.

Also, instead of using min and max you could use $array[0] and $array[-1] - the list is sorted.

Also, as far I can see, you check if value is out of bounds every time loop passes. You can move this check outside loop.


Comment on Re: Improve my lookup script
Select or Download Code
Re^2: Improve my lookup script
by jjap (Monk) on Aug 22, 2012 at 15:46 UTC
    Indeed all very good points!

    Thanks for pointing me to List::BinarySearch.

     bsearch_num_pos($lookup, @array) gives me a grip to handle further calculations.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989073]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-12-22 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (117 votes), past polls