develooper Front page | perl.perl5.porters | Postings from July 2001

if then else otherwise ...

Thread Next
From:
Brent Dax
Date:
July 29, 2001 09:05
Subject:
if then else otherwise ...
Message ID:
FJELLKOPEAGHOOODKEDPAEFPCDAA.brentdax1@earthlink.net
# This makes no sense. ?: tests a boolean value, which is either true or false.
# There is no ternary state for a boolean value. True/False, Yes/No, On/Off,
# 1/0. Are you suggesting Yes/No/Maybe? Or are you redefining True and False?

No.  He's effectively saying this:

condition ? executed-if-positive : executed-if-zero : executed-if-negative

It doesn't quite fit into simple boolean logic.  This has the potential to be useful for sorters:

@indices=sort { $ary[$a] <=> $ary[$b] ? -1 : 0 : 1 } @indices;	#sort by values of another array in
reverse order

Yes, that last example can be done with a simple $ary[$b] <=> $ary[$a], but I'm trying to show you
what this feature does and I just woke up so my brain isn't up and running yet.  :^)

# Doesn't matter. What you're asking has no counterpart in boolean logic, and
# as such would make no sense in any computer language. You may have an idea,
# but you are saying it wrong if you do.

There are plenty of things that have no counterpart in boolean logic.  Where are loops defined in
Boolean logic?

--Brent Dax
brentdax1@earthlink.net


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About