Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Perl provides three logical operators: &&, ||, and !, and they have the same meaning as in C.

Wiki MarkupPerl also provides three alternative logical operators: {{and}}, {{or}}, and {{not}}. They have the same meanings as {{&&}}, {{||}}, and {{\!}}. They have much lower binding precedence, which makes them useful for control flow \[ [Wall 2011|AA. Bibliography#Manpages]\]. They are called the late-precedence logical operators, whereas {{&&}}, {{||}}, and {{!}} are called the early-precedence logical operators.

It is possible to mix the early-precedence logical operators with the late-precedence logical operators, but this mixture of precedence often leads to confusing, counterintuitive behavior. Therefore, every Perl expression should use either the early-precedence operators or the late-precedence ones, never both.

Wiki Markup\[[Conway 2005|AA. Bibliography#Conway 2005]\] recommends avoiding the use of {{not}} and {{and}} entirely and using {{or}} only in control-flow operations, as a failure mode:

Code Block
langperl
    print $filehandle $data    or croak("Can't write to file: $!");

...

Tool

Diagnostic

Perl::Critic

ValuesAndExpressions::ProhibitMixedBooleanOperators

Bibliography

Wiki Markup\[[CPAN|AA. Bibliography#CPAN]\] [Elliot Shank, Perl-Critic-1.116|http://search.cpan.org/~elliotjs/ Perl-Critic-1.116/] [ProhibitMixedBooleanOperators|http://search.cpan.org/~elliotjs/Perl-Critic-1.112_001/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitMixedBooleanOperators.pm] \[[Conway 2005|AA. Bibliography#Conway 2005]\] pg. 70 \[[Wall 2011|AA. Bibliography#Manpages]\] [perlop|http://perldoc.perl.org/perlop.html] ProhibitMixedBooleanOperators
[Conway 2005] pg. 70
[Wall 2011] perlop

...

      02. Expressions