From the course: Perl 5 Essential Training
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Else and elsif - Perl Tutorial
From the course: Perl 5 Essential Training
Else and elsif
- [Voiceover] The if statement also provides for alternate branches using else and elsif. Here's a working copy of conditional.pl from chapter five of the exercise files. And I'm just going to come down here and I'm going to say else say "false" or I'll just put the word "else" in there. We can see that the else condition is executing. So if I go ahead and run this, you see it says true. If I change this to say x is 47, then the else is executed instead of the true. So this second block after else with those curly braces there, that is what is executed when the condition is false. So I'll change this back to one and I'm going to add an elsif. I'm going to say elsif, and in Perl it is spelled with the s. I get confused because I use so many languages. $x equals say five. And I can say "five". And I can add a couple more if I want to. You can test for six and seven. And I can just write these in here, six and seven. And now if I run this, of course we have one. But if I change this to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.