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 ternary conditional operator

The ternary conditional operator - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

The ternary conditional operator

- [Voiceover] There is one more conditional structure you should know about: the ternary conditional operator, which is borrowed straight from C. It's a little confusing to look at if you are not already familiar with it, but it works really, really well. Here is a working copy of conditional.pl from chapter five of the exercise files. And I'm actually just gonna get rid of all of that, and I'm gonna say, if you want to know which of these x or y is actually greater than the other, and I'm gonna make one of them greater than the other, easy way to do this is to say something like this: say $x greater than $y, question mark, x, colon, y. Like that. So, how this works is it will return one of these two values, either the x or the y, depending upon the condition. If the condition is true, it'll return the first one, if the condition is not true, it will return the second one. So when I run this, it says "y is greater than x". If I make them the same, then it's still gonna say "y"…

Contents