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

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -