On 04/07/2012 06:54 AM, Peter Scott wrote:
> On Wed, 04 Apr 2012 03:04:42 -0400, Uri Guttman wrote:
>> that code is not a good use of ?: at all so use if/else.
>
> Right. And if you want the single statement succinctness, use and/or:
>
> % perl -le '%test = qw(one first two second); $test{one} eq "first" and
> $test{one} .= " is the worst" or $test{two} .= " is the best"; print for
> values %test'
> first is the worst
> second
>
> % perl -le '%test = qw(one third two second); $test{one} eq "first" and
> $test{one} .= " is the worst" or $test{two} .= " is the best"; print for
> values %test'
> third
> second is the best
however much i respect peter, i disagree here. and/or are low precedence
and work well here but using them for completely different assignments
just to make a single statement is overkill. maybe in a one liner but
how many one liners need code this complex (if needed, it shouldn't be a
one liner). the code here should be a classic if/else and no other way.
uri
Thread Previous