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 = ''
}
The value of $model->test is going to be either "1" or undefined. If there’s something in $model->test, set $review to "1" otherwise set it equal to ''.
Because it’s not Perl 5.10 I can’t use the new swanky defined-or operator. My first reaction was to use the ternary operator like this…
defined($model->test) ? $review = "1" : $review = '';
but that didn’t work either.
Does anyone have an idea how to assign this more efficiently?
Janie
I’d usually write this as:
where the parentheses are for clarity for other people reading the code.