That's not correct. The ternary operator will generate some sort of value - what you do with that value is up to you. You could, for example, use it to create a boolean return value:
return defined $result ? 1 : 0;
You can also nest ternary operators. Say you wanted to compare two numbers and produce: 1 if the first number was bigger; 0 if they were the same; -1 if the second number was bigger:
my $cmp = $x > $y ? 1 : $x == $y ? 0 : -1;
-- Ken
In reply to Re^3: Short form (ternary) if else
by kcott
in thread Short form (ternary) if else
by gg48gg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |