Is Perl optimized to skip remaining logic operands if the answer is already decided?

后端 未结 6 1774
悲&欢浪女
悲&欢浪女 2020-12-21 04:22

For instance, I need to match some text if $do eq \'b\'. If I run this code:

if (($do eq \'b\') && (/text/))
{
do stuff
}
6条回答
  •  渐次进展
    2020-12-21 04:55

    It would be

    if ($do eq 'b' && /text/) {
        do stuff
    }
    

    Yes - if $do eq 'b' is false, /text/ won't be evaluated.

提交回复
热议问题