我该如何做以下事情:
(condition) ? (do this) (do this too) : (just do this then)
答案 0 :(得分:8)
使用do
执行此操作。
condition ? do { this(); this_too(); } : the_other_thing()
答案 1 :(得分:2)
你想:
( (do this), (do this too) )
答案 2 :(得分:-3)
执行以下操作的示例程序:
#!/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");