in reply to Re^6: Check word presence WITHOUT hashes or grep
in thread Check word presence WITHOUT hashes or grep

You're getting there. Now you are returning the index if the word was found and undef if it wasn't, and you get a warning when you compare undef == 0. You could change your if statement to if ( ! defined $index ). Your words not being found may be because you should be doing while ($low <= $high). The way you have it, you are quitting when you've narrowed down the range to one element instead of checking that element.
Looking at the "Mastering algorithms with perl" O'Reilly Book, it turned out that I had to do $high = $cur - 1 and not +1, to adjust $high.
Sorry, my mistake.

Replies are listed 'Best First'.
Re^8: Check word presence WITHOUT hashes or grep
by gojippo (Novice) on May 01, 2008 at 06:55 UTC
    I corrected my script with your propositions, and now it works just fine. So thank you, ysth, and thank you all perl monks.
    I learned a lot thanks to you and finally got a script up and working.