http://www.perlmonks.org?node_id=1026180


in reply to Re^2: Binary search
in thread Binary search

This line will produce a non-integer value with an odd number of elements, which can't be an index of an array.

$mid=($low+$high)/2;
If you use the following at the top of your scripts and make the necessary corrections for it to compile, it will make your life easier and your code better.
use strict; use warnings;

Update: I see now that an array can be indexed with a non-integer value, effectively truncating the fractional part. I'm surprised that gives no warning.

use strict; use warnings; use feature 'say'; my @list = 0..9; say $list[2.5]; say $list[2.01]; say $list[2.99]; # all these print '2'
golux is correct of course about the sort, which is something that enabling 'strict' and 'warnings' would pick up.