my @array = @$arrayref; my $word = $$wordref;
Why copy all this data? Why not just use $arrayref $wordref directly?
while ($lo <= :w $hi) {
What is the meaning of :w in the code? That looks like a syntax error.
$lo = ++$try; # without increment there will be ... $hi = --$try;
Why are you modifying $try? It always gets assigned from int(($lo + $hi)/2) at the top of the loop.
if ($array[$try] lt $word) { $lo = ++$try; # without increment there will be # a dead loop in the 4th case, # see the note at the bottem next } elsif ($array[$try] gt $word) { $hi = --$try; next } else { return $try }
The use of next is superfluous because of the way that if elsif else works.
In reply to Re: Binary search algorithm.
by jwkrahn
in thread Binary search algorithm.
by kindlychung
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |