Re: perl flawed or my fault

anno4000@xxxxxxxxxxxxxxxxxxxxxx wrote:
John W. Krahn <krahnj@xxxxxxxxx> wrote in comp.lang.perl.misc:
anno4000@xxxxxxxxxxxxxxxxxxxxxx wrote:

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 assume that you meant to write:

( $list->[ $mid] le $targ ? $low : $high ) = $mid;

because your example never assigns a value to $low.


perl -le '$_ ? $low : $high = 123 for 0, 1; print "$low $high"'


123 123

showing that both are set.

Yes, interesting, even though the Fine Manual states:

The operator may be assigned to if both the 2nd and 3rd arguments are
legal lvalues (meaning that you can assign to them):

($a_or_b ? $a : $b) = $c;

Because this operator produces an assignable result, using assignments
without parentheses will get you in trouble.

Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall