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.

Relational operators

Relational operators - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Relational operators

- [Voiceover] The relational operators are used to compare values in a logical context. Here's a working copy of relational.pl from chapter eight of the exercise files. Relational operators return a value of true or false. Now in Perl, anything that is empty or zero is considered false and anything else is considered true. In general, the relational operators will return the number one for true and an empty string for false. These operators are typically used in conditional context. For example, in this if statement here on line 12, if $a is equal to $b. Now this is the relational operator that tests for numeric equality. It works for numbers, and it does not work for strings. So testing of $a equals $b, of course $a is 7 and $b is 42. So if I run this, I will get the result that says false. And if I change this to say if $a equals $c which is also 7 like $a and I run it, then it says true. Now some of these relational operators include the not equal to. So I can run that, and now…

Contents