Special variable to read out ||-match

Discussion in 'Perl Misc' started by Bart Van der Donck, Jun 1, 2006.

  1. Hello,

    In this code

    if ( 1 == 1
    || 1 == 2
    || 0 == 0
    || 2 == 5 ) {
    print "You're here because check 1 and 3 where okay.";
    }

    Is there a possibility to readout which checks were positive and which
    negative in the ||-series ?

    Thank you

    --
    Bart
    Bart Van der Donck, Jun 1, 2006
    #1
    1. Advertising

  2. Bart Van der Donck wrote:
    > Hello,
    >
    > In this code
    >
    > if ( 1 == 1
    > || 1 == 2
    > || 0 == 0
    > || 2 == 5 ) {
    > print "You're here because check 1 and 3 where okay.";
    > }
    >
    > Is there a possibility to readout which checks were positive and which
    > negative in the ||-series ?


    not in that code. you would short circuit on the first true condition.
    if you had separate 'if' statements for each condition, and set a flag
    for each condition that was true, with each flag representing a bit,
    you could sum the bits together and come up with a decimal
    representation of a binary number that represents the 'check numbers'
    that were true. so in this case 1 and 3 being true would correspond to:
    1010 ( up to you to decide if you want to go left-to-right or
    vice-versa). 1010 would equate to 10.
    it_says_BALLS_on_your_forehead, Jun 1, 2006
    #2
    1. Advertising

  3. it_says_BALLS_on_your_forehead wrote:

    > Bart Van der Donck wrote:
    > > Hello,
    > >
    > > In this code
    > >
    > > if ( 1 == 1
    > > || 1 == 2
    > > || 0 == 0
    > > || 2 == 5 ) {
    > > print "You're here because check 1 and 3 where okay.";
    > > }
    > >
    > > Is there a possibility to readout which checks were positive and which
    > > negative in the ||-series ?

    >
    > not in that code. you would short circuit on the first true condition.
    > if you had separate 'if' statements for each condition, and set a flag
    > for each condition that was true, with each flag representing a bit,
    > you could sum the bits together and come up with a decimal
    > representation of a binary number that represents the 'check numbers'
    > that were true. so in this case 1 and 3 being true would correspond to:
    > 1010 ( up to you to decide if you want to go left-to-right or
    > vice-versa). 1010 would equate to 10.


    Thanks it_says_BALLS_on_your_forehead. I've found a similar workaround.

    --
    Bart
    Bart Van der Donck, Jun 5, 2006
    #3
  4. Bart Van der Donck wrote:
    > it_says_BALLS_on_your_forehead wrote:
    >
    > > Bart Van der Donck wrote:
    > > > Hello,
    > > >
    > > > In this code
    > > >
    > > > if ( 1 == 1
    > > > || 1 == 2
    > > > || 0 == 0
    > > > || 2 == 5 ) {
    > > > print "You're here because check 1 and 3 where okay.";
    > > > }
    > > >
    > > > Is there a possibility to readout which checks were positive and which
    > > > negative in the ||-series ?

    > >
    > > not in that code. you would short circuit on the first true condition.
    > > if you had separate 'if' statements for each condition, and set a flag
    > > for each condition that was true, with each flag representing a bit,
    > > you could sum the bits together and come up with a decimal
    > > representation of a binary number that represents the 'check numbers'
    > > that were true. so in this case 1 and 3 being true would correspond to:
    > > 1010 ( up to you to decide if you want to go left-to-right or
    > > vice-versa). 1010 would equate to 10.

    >
    > Thanks it_says_BALLS_on_your_forehead. I've found a similar workaround.


    cool :).
    it_says_BALLS_on_your forehead, Jun 5, 2006
    #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. hiwa
    Replies:
    0
    Views:
    628
  2. Victor
    Replies:
    2
    Views:
    629
    Victor
    May 17, 2004
  3. ekzept
    Replies:
    0
    Views:
    356
    ekzept
    Aug 10, 2007
  4. John Gordon
    Replies:
    13
    Views:
    462
    Ian Kelly
    Dec 20, 2011
  5. Volkan Civelek

    Match doesn't match

    Volkan Civelek, Jul 19, 2006, in forum: Ruby
    Replies:
    4
    Views:
    154
Loading...

Share This Page