|There's more than one way to do things|
Re^3: Binary searchby golux (Hermit)
|on Mar 29, 2013 at 17:39 UTC||Need Help??|
Did you try printing out the sorted list to make sure it got sorted correctly?
I did, and got:
So the sort isn't working. Now that I know that's a problem, I look at your sort line more carefully:
And it's obvious what's wrong; you should use "$a" and "$b". You would have found that if you used the "strict" and "warnings" pragmas. Try running this partial program and you'll see:
The other (potential) problem I can see is that you are not doing integer math, so when you take the average of $low and $high with:
you're sometimes getting a fractional result. You may need to use int to fix that.
Try those fixes to start with and see if you can get farther. One other recommendation would be to put print statements at various locations in your code to make sure you're getting the expected results each time through the loop.