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.

The if statement

The if statement - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

The if statement

- [Voiceover] Pearl provides a complete set of conditional branch statements starting with the basic if. Here's a working copy of conditional.pl from chapter five of the exercise files. The if statement is probably the most common conditional in Pearl, or in most language. So it seems like a good place for us to start. The if keyword, as you can see down here on line 10, the if keyword is followed by a logical condition in parentheses. You can see there it's $x == 1. That double equals sign is the conditional test for equality and the condition is evaluated first, and if it's true the block of code is executed. And you see that block of code here starting with this curly brace ending with that curly brace on line 12. If the condition is not true, then the next line of code after the block is executed, and the code inside the block is never executed. Either way, after the block is executed then the next line of code is run anyway. So if I go ahead and run this, you see it prints true…

Contents