in reply to Re^2: Short form (ternary) if else
in thread Short form (ternary) if else
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Short form (ternary) if else
by Marshall (Canon) on Feb 08, 2012 at 22:26 UTC | |
|
Re^4: Short form (ternary) if else
by gg48gg (Sexton) on Feb 08, 2012 at 22:35 UTC | |
by kcott (Archbishop) on Feb 08, 2012 at 23:06 UTC | |
by Riales (Hermit) on Feb 08, 2012 at 23:20 UTC | |
by wrog (Friar) on Feb 08, 2012 at 23:32 UTC | |
by Riales (Hermit) on Feb 08, 2012 at 23:43 UTC | |
by kcott (Archbishop) on Feb 08, 2012 at 23:59 UTC | |
by gg48gg (Sexton) on Feb 09, 2012 at 00:05 UTC | |
by AnomalousMonk (Archbishop) on Feb 09, 2012 at 03:07 UTC | |
by Marshall (Canon) on Feb 09, 2012 at 00:06 UTC | |
|
Re^4: Short form (ternary) if else
by gg48gg (Sexton) on Feb 08, 2012 at 22:10 UTC | |
by Riales (Hermit) on Feb 08, 2012 at 22:22 UTC |