Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: assigning the maximum of two numbers

by ikegami (Patriarch)
on Nov 04, 2005 at 20:15 UTC ( [id://505862]=note: print w/replies, xml ) Need Help??


in reply to Re^2: assigning the maximum of two numbers
in thread assigning the maximum of two numbers

I saw that used a lot over 15 years ago in BASIC code. BASIC didn't have a ternary conditional operator, but it was possible to emulate it.
$a = $i > $j ? 6 : 10;
could be written as the following in BASIC (knowing that false is 0 and true is -1):
LET a = (i > j) * 4 + 10;
just as it could be written as the following in Perl (knowing that false is 0 and true is 1):
$a = ($i > $j) * -4 + 10;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://505862]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2024-04-24 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found