perl - Writing (A && C) || (B && C) conditional shorter -


(e.g. in perl) when either condition or condition b have same consequence

if (a){     # consequence x }elsif (b){     # consequence x } 

we can write

if ( || b ) {      # consequence x } 

how have following condition: either when , c true, or b , c true, consequence c follows.

this can written long:

if ( && c){       # consequence x } elsif (b && c ){       # consequence x } 

my question is, there way write shorter? this:

if ( (a && c) || (b && c) )  

is syntactically ok ???

yes.

if ( && c){       # consequence x } elsif (b && c ){       # consequence x } 

is same as:

if ( (a && c) || (b && c) ){     #consequence x } 

and avoids evaluating c twice:

if ( (a || b) && c){     #consequence x } 

btw, more logical question, logic here isn't limited perl.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -