in reply to Re: Re: Trinary or If'n'Else?
in thread Trinary or If'n'Else?

I'm not sure I understand. As far as I can see, ?: and &&|| do the same thing:
print 1 ? 'true' : 'false'; # True print 1 && 'true' || 'false'; # True print 0 ? 'true' : 'false'; # False print 0 && 'true' || 'false'; # False
In both a ? b : c and a && b || c, a is a boolean expression. What can ?: do that &&|| cannot?

Replies are listed 'Best First'.
(tye)Re: Trinary or If'n'Else?
by tye (Sage) on Dec 22, 2000 at 09:32 UTC

    I quickly came up with at least two:

    DB<1> x 0 && qw(t r u e) || qw(f a l s e) 0 'f' 1 'a' 2 'l' 3 's' 4 'e' DB<2> x 1 && qw(t r u e) || qw(f a l s e) 0 'e' # Oops! DB<3> x 1 && 2 || "two" 0 2 DB<4> x 1 && 0 || "two" 0 'two' # Oops!
    So "b" can't be a false value and can't be a list.

            - tye (but my friends call me "Tye")
Re: Re: Re: Re: Trinary or If'n'Else?
by I0 (Priest) on Dec 24, 2000 at 03:20 UTC