# Special variable to read out ||-match

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

1. ### Bart Van der DonckGuest

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

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.

3. ### Bart Van der DonckGuest

> 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

Bart Van der Donck 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 .