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.

Negative conditionals with unless

Negative conditionals with unless - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Negative conditionals with unless

- [Voiceover] Perl also provides a negative version of the if statement called unless. Here's a working copy of conditional.pl from Chapter five of the exercise files. And I'm just going to change this here to say unless, with the unless here, and when I run this, you notice the condition is true and so unless is not run and if I change this one to a seven, and run now, you see unless is displayed so the condition is false and so unless, the unless clause is run. And likewise, we can have an else here, and if I change this back to a one, you see the else is run instead of the unless. This is not very common. It's usually clearer to use something like, if x is not equal to one, what's more common is to use this in the post fix notation, so we could do something like, say, these are the same unless $x is equal to $y and if I save and run this, we'll make this not equal to rather, and then it says these are the same unless x is not equal to y. So the unless statement is simply the…

Contents