Youch, that's completely wrong.
First of all, the basic idea is wrong. Relational operators (like >) have higher precedence than the conditional operator (?:), so attempting to raise the precendence of > using parens is a no-go. (See perlop.) *
Furthermore, you actually made things worse by adding the parens because
push ($cond > 0) ? @a : @b, $elem;
is the same as
push($cond > 0) ? @a : @b, $elem;
is the same as
(push($cond > 0)) ? @a : @b, $elem;
which is quite wrong.
Finally, even if done right, the parens don't help. Both
push(($cond > 0) ? @a : @b, $elem);
and
push((($cond > 0) ? @a : @b), $elem);
produce the same result as the OP.
* — You might be thinking of the assignment operators rather than relational operators. Since the conditional operator (?:) has higher precedence than the assignment operators (like =), $cond ? $a = 1 : $b = 1; means ($cond ? $a = 1 : $b) = 1;.
In reply to Re^2: Using ternary operator as lvalue in push
by ikegami
in thread Using ternary operator as lvalue in push
by oha
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |