There's a good discussion on Binary Searches with Perl in Mastering Algorithms with Perl (O'Reilly). I know this is probably homework, but if you need to see several different ways to implement a Binary Search in Perl you can view the source for List::BinarySearch. One of the methods used is adapted from the book mentioned above, and the other methods were based on a composite from several sources including Wikipedia and a couple of other algorithms books I happened to have.
But moritz is right: If your list isn't sorted to begin with, a Binary Search won't produce useful results. You'll either need to sort the list, or do a linear search.
Dave
In reply to Re: Binary search
by davido
in thread Binary search
by akvats01
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |