What is the difference between Perl's ( or, and ) and ( ||, && ) short-circuit operators?

前端 未结 5 1410
暖寄归人
暖寄归人 2020-11-29 06:44

Which of these subroutines is not like the other?

sub or1 {
    my ($a,$b) = @_;
    return $a || $b;
}

sub or2 {
    my ($a,$b) = @_;
    $a || $b;
}

sub          


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 06:59

    Both versions are short-circuiting in Perl, but the 'textual' forms ('and' and 'or') have a lower precedence than their C-style equivalents.

    http://www.sdsc.edu/~moreland/courses/IntroPerl/docs/manual/pod/perlop.html#Logical_And

提交回复
热议问题