if statement - nested IFs or multiple condition in single IF - perl -


i have piece of code multiple conditions in perl

if (/abc/ && !/def/ && !/ghi/ && jkl) {  #### } 

will every condition evaluated @ once on every line?

i can prioritize conditions using nested ifs

if (/abc/){    if (!/def/){    ....so on  } 

&& short-circuits. evaluates rhs operand if needed. if it's lhs operand returns false, && value.

for example,

use feature qw( ); sub f1 { "1"; 1 } sub f2 { "2"; 0 } sub f3 { "3"; 0 } sub f4 { "4"; 0 } 1 if f1() && f2() && f3() && f4(); 

output:

1 2 

so following 2 lines same:

if (/abc/) { if (!/def/) { ... } }  if (/abc/ && !/def/) { ... } 

in fact, if compiles and operator, above close to

(/abc/ , !/def/) , { ... };  (/abc/ && !/def/) , { ... }; 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -