Menu

Post image 1
Post image 2
1 / 2
0

Beautiful Perl feature: low-precedence boolean operators 'and', 'or'

DEV Community·Laurent Dami·24 days ago
#txSiY3js
Reading 0:00
15s threshold

Beautiful Perl series This post is part of the beautiful Perl features series. See the introduction post for general explanations about the series. Today's feature is quite unique in programming languages: the fact that Perl has two different syntaxes for expressing the same boolean operations. Read on to understand why this is clever and beautiful. Boolean algebra and short-circuit evaluation The basic operations of Boolean algebra are fundamental in programming; therefore they are present in all programming languages. In the C language, later followed by many other languages, icluding Perl, logical conjunction (the "AND" operator) is written && , logical disjunction (the "OR" operator) is written || , and logical negation (the "NOT" operator) is written ! . Conjunction has higher precedence than disjunction, so a && b || c && d is parsed as (a && b) || (c && d) and not a && (b || c) && d . The unary negation operator has even higher precedence.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More