What kind of syntactic sugar is available in Perl to reduce code for l/rvalue operators vs. if statements?

后端 未结 5 1473
时光说笑
时光说笑 2021-02-13 04:26

There\'s a bunch out there, as Perl is a pretty sugary language, but the most used statements in any language is the combination of if statements and setting values. I think I\

5条回答
  •  不思量自难忘°
    2021-02-13 04:43

    There's also the left hand side ternary operator:

    $cond ? $var1 : $var2 = "the value";
    

    is equivalent to:

    if ($cond) {
        $var1 = "the value";
    } else {
        $var2 = "the value";
    }
    

提交回复
热议问题