Assignment inside Perl ternary conditional operator problems

前端 未结 5 1605
一生所求
一生所求 2021-02-05 00:57

This snippet of Perl code in my program is giving the wrong result.

$condition ? $a = 2 : $a = 3 ;
print $a;

No matter what the value of

5条回答
  •  无人共我
    2021-02-05 01:17

    One suggestion to Tithonium's answer above:

    If you are want to assign different values to the same variable, this might be better (the copy-book way):

    $a = ($condition) ? 2 : 3;

提交回复
热议问题