in reply to Re: variable set to 0 ? 0 : 1
in thread variable set to 0 ? 0 : 1
or you can "chain" ternary operators by using another ternary as the false-branch of the previous:$i == 15 ? push @str, $_ : $j = $i += 1;
which would otherwise have to be a hideously ugly and thrice as repetitive thing like this:my $res = $cmd eq "add" ? $x + $y : $cmd eq "sub" ? $x - $y : $cmd eq "mul" ? $x * $y : $cmd eq "div" ? $x / $y : undef;
my $res; if ($cmd eq "add") { $res = $x + $y } elsif($cmd eq "sub") { $res = $x - $y } elsif($cmd eq "mul") { $res = $x * $y } elsif($cmd eq "div") { $res = $x / $y } else { $res = undef }
Makeshifts last the longest.
|
|---|