Re: perl flawed or my fault

anno4000@xxxxxxxxxxxxxxxxxxxxxx writes:
I am of a split mind about using ?: in lvalue context. It *is*
kind of obscure, but there are situations that simply call for
it. One is the loop of a binary search, for example

while ( $low < $high - 1 ) {
my $mid = ($low + $high)/2;
$list->[ $mid] le $targ ? $low : $high = $mid;

The if-else equivalent to ?: is four lines, even cuddling the else.
I can never bring myself to use it.

I don't object to that so much, but I'd still use the if-else
equivalent (and cuddle the else too! Bwahahahah!) just because I
think it's more readable.


Relevant Pages

  • The real kooks.
    ... attitude along the lines of " Why is everyone stupid except for me? ... the code below uses a binary search to look up a Non_ASCII, Unicode character; ... LOOP {// This LOOP is the heart of the binary search. ...
  • Re: Search algorithm to use
    ... a linear search will correctly predict nearly all the ... branches, while a binary search will mispredict half of them, on ... binary search will tend to cause more cache misses, ... >> search loop, one for the element compare, and one for the loop test, ...
  • Re: [OT] Switch question
    ... >>a byte code interpreter I am working on, and I am wondering if I should take ... >>any steps to optimise this loop. ... The binary search works by first testing for the ...
  • Re: Search algorithm to use
    ... >> order, and the array is less than 50 elements, and I want to find the ... >A linear search will take about 25 compares on the average. ... >A binary search will take about 6 compares on the average. ... search loop, one for the element compare, and one for the loop test, ...
  • Re: Binary search in Matlab
    ... > exist a way to make this without loop. ... Since a binary search is inherently an iterative ... homework problem. ... The best material model of a cat is another, or preferably the same, cat. ...