Reputation: 69
How can I do something like the following:
(condition) ? (do this) (do this too) : (just do this then)
Upvotes: 3
Views: 2452
Reputation: 118605
Do this and this too with do
.
condition ? do { this(); this_too(); } : the_other_thing()
Upvotes: 10
Reputation: 1
A sample program that does that follows:
#!/usr/bin/perl
my $a = 1;
$result = ($a > 1) ? (print "\nDo this\n") ? (print "\nDo this also\n") ? "" :
(print "\nOr else do this\n");
$a = 6;
$result = ($a > 1) ? (print "\nDo this\n") ? (print "\nDo this also") ? "" :
(print "\nOr else do this\n");
Upvotes: -3