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 values

Logical values - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Logical values

- [Voiceover] Logical values are used for controlling conditionals and loops. Here's a working copy of Logical.pl from Chapter 4 of the execise files. A logical value has one of two states, true or false. For example, in this case if x is equal to y down there on line 10, if x is equal to y and we know that x is 1 and y is 1, so x is equal to y so it should say true. I'm going to go ahead and build and you see when I run it, it says true. The If statement takes a logical value to decide which block of code will be executed. We'll cover If and other conditionals in a later chapter. The double equals sign tests for equality and it returns true is the values are equal and false is they are not. In this case, $x is equal to $y, so the logical value is true. Now, just like in the C language, zero is false and non-zero is true. If I say zero here and run it, it says false but if I say any value that's not zero and save and run that, then it says true. Because of Perl's duck-typing model…

Contents