compound conditional

B

Bob

Can I create a compound conditional with the :? shortform?
I tried putting two statements in curly brackets but that didn't work.

I ended up using if-then but I didn't want to take up much source room
(it only sets a variable to "is" or "are" text :)).
 
T

Tad McClellan

Bob said:
Can I create a compound conditional with the :? shortform?

Yes.


I tried


If you show your code we can help fix your code.

If you don't, we can't.

putting two statements in curly brackets but that didn't work.


You can't just make shit up and expect the computer to know what you mean.

I ended up using if-then but I didn't want to take up much source room
(it only sets a variable to "is" or "are" text :)).


my $to_be = singular($txt) ? 'is' : 'are';
 
M

Matija Papec

X-Ftn-To: Bob

Bob said:
Can I create a compound conditional with the :? shortform?
I tried putting two statements in curly brackets but that didn't work.

Did you also tried ?:
? :)
 
J

Joe Smith

Bob said:
Can I create a compound conditional with the :? shortform?

Yes, I can.

(home/jms) jms@mathras> cat test.pl
sub whichbit {
$num = shift;
$num & 0x80 ? 'bit 7' :
$num & 0x40 ? 'bit 6' :
$num & 0x20 ? 'bit 5' :
$num & 0x10 ? 'bit 4' :
$num & 0x08 ? 'bit 3' :
$num & 0x04 ? 'bit 2' :
$num & 0x02 ? 'bit 1' :
$num & 0x01 ? 'bit 0' :
'none';
}

foreach (0 .. 17) {
print "The highest bit set in $_ is ",whichbit($_),"\n";
}

(home/jms) jms@mathras> perl test.pl
The highest bit set in 0 is none
The highest bit set in 1 is bit 0
The highest bit set in 2 is bit 1
The highest bit set in 3 is bit 1
The highest bit set in 4 is bit 2
The highest bit set in 5 is bit 2
The highest bit set in 6 is bit 2
The highest bit set in 7 is bit 2
The highest bit set in 8 is bit 3
The highest bit set in 9 is bit 3
The highest bit set in 10 is bit 3
The highest bit set in 11 is bit 3
The highest bit set in 12 is bit 3
The highest bit set in 13 is bit 3
The highest bit set in 14 is bit 3
The highest bit set in 15 is bit 3
The highest bit set in 16 is bit 4
The highest bit set in 17 is bit 4

-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top