3 ms·
This thread is about needing an implicit return. So my "ditto" is 100% correct! But you are quite right that Perl if/else are statements and not expressions.
by draegtun 16y ago
This thread is about needing an implicit return. So my "ditto" is 100% correct!
But you are quite right that Perl if/else are statements and not expressions. Instead you can use the ternary operator:
my $value = $cond == 1 ? 'true' : 'false';
And because of ditto for Perl you can also do following:
my $value = do { if ($cond == 1) { 'true' } else { 'false' } };