Re: perl flawed or my fault
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Tue, 03 Oct 2006 19:56:56 GMT
anno4000@xxxxxxxxxxxxxxxxxxxxxx wrote:
John W. Krahn <krahnj@xxxxxxxxx> wrote in comp.lang.perl.misc:
anno4000@xxxxxxxxxxxxxxxxxxxxxx wrote:
while ( $low < $high - 1 ) {I assume that you meant to write:
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.
( $list->[ $mid] le $targ ? $low : $high ) = $mid;
because your example never assigns a value to $low.
Hmmm?
perl -le '$_ ? $low : $high = 123 for 0, 1; print "$low $high"'
prints
123 123
showing that both are set.
Yes, interesting, even though the Fine Manual states:
<QUOTE>
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.
</QUOTE>
John
--
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
.
- Follow-Ups:
- Re: perl flawed or my fault
- From: anno4000
- Re: perl flawed or my fault
- References:
- perl flawed or my fault
- From: paul
- Re: perl flawed or my fault
- From: Eric Schwartz
- Re: perl flawed or my fault
- From: anno4000
- Re: perl flawed or my fault
- From: John W. Krahn
- Re: perl flawed or my fault
- From: anno4000
- perl flawed or my fault
- Prev by Date: Re: perl flawed or my fault
- Next by Date: Re: OS X and perldoc
- Previous by thread: Re: perl flawed or my fault
- Next by thread: Re: perl flawed or my fault
- Index(es):