Logical Operators

Let's discuss logical operators and how we can use them to evaluate our conditions in Perl.

What are logical operators?

Logical operators are used for combining conditional statements. This means that the program can take a decision based on multiple conditions. We will learn more about conditional statements later. But for now, suffice it to say that conditional statements are those that can either be “true” or “false”.

Types of logical operators

There are three logical operators:

  • && or and
  • || or or
  • ! or not

The and operator

The and or && operator returns true if all the statements are true. It returns false if one or more statements are false. Let’s say that we have two statements a and b. The following table illustrates this behavior:

a b a && b or a and b
true true true
true false false
false true false
false false false

Run the code below to see how this works:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy