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

Due to the low precedence of the ‘or’ operator, or3 parses as follows:

sub or3 {
    my ($a,$b) = @_;
    (return $a) or $b;
}

The usual advice is to only use the ‘or’ operator for control flow:

@info = stat($file) or die;

For more discussion, see the perl manual: http://perldoc.perl.org/perlop.html#Logical-or-and-Exclusive-Or

Leave a Comment