compound conditional

Discussion in 'Perl Misc' started by Bob, Apr 24, 2005.

  1. Bob

    Bob Guest

    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 :)).
    Bob, Apr 24, 2005
    #1
    1. Advertising

  2. Bob <> wrote:

    > 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';


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Apr 24, 2005
    #2
    1. Advertising

  3. Bob

    Matija Papec Guest

    X-Ftn-To: Bob

    Bob <> wrote:
    >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 ?:
    ? :)


    --
    Matija
    Matija Papec, Apr 24, 2005
    #3
  4. Bob

    Joe Smith Guest

    Bob wrote:
    > 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
    Joe Smith, Apr 25, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWlrZUw=?=
    Replies:
    0
    Views:
    380
    =?Utf-8?B?TWlrZUw=?=
    Nov 19, 2004
  2. Damir Mikoc

    CMR/CMP and Compound Primary Key

    Damir Mikoc, Jul 3, 2003, in forum: Java
    Replies:
    1
    Views:
    551
    Christopher Blunck
    Jul 4, 2003
  3. Apc
    Replies:
    1
    Views:
    837
  4. Alec S.
    Replies:
    10
    Views:
    10,084
    Alec S.
    Apr 16, 2005
  5. Replies:
    3
    Views:
    854
    Steve Holden
    Sep 16, 2003
Loading...

Share This Page