Assigning using ternary operator?

后端 未结 7 866
猫巷女王i
猫巷女王i 2021-02-01 03:56

I am on Perl 5.8 and am needing to assign a default value. I ended up doing this:

if ($model->test) {
    $review = \"1\"
} else {
    $review = \'\'
}
         


        
7条回答
  •  太阳男子
    2021-02-01 04:35

    I'd usually write this as:

    $review = ( defined($model->test) ? 1 : '' );
    

    where the parentheses are for clarity for other people reading the code.

提交回复
热议问题