From the course: Perl 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Logical operators

Logical operators - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Logical operators

- [Voiceover] Logical operators are used to perform Boolean operations on logical values. Here's a working copy of relational.pl from chapter eight of the exercise files. Perl has two sets of logical operators for two different purposes. Low precedence logical operators are used to bind logical expressions according to Boolean rules. For example, we have this conditional expression here that we used earlier in this chapter, and if I run this you see it says false, because a is not actually equal to b, a is a seven, and b is 42. Now if I come down here and I say if a equals b, or rather, if a equals c, and $b is equal to $d, we notice that a is equal to c, and b is equal to d, so we should get true. And I'll run that, and you see that the result is true. So this and, right there, is a logical operator. It's very low priority, and so the expressions on either side of it are always going to be evaluated first. And this makes it very useful for this sort of usage. Now, just so that we can…

Contents