3 ms·
Not really: for example, if/else statements are not expressions whose results can be assigned to a variable like in Ruby.
by Andys 16y ago
Not really: for example, if/else statements are not expressions whose results can be assigned to a variable like in Ruby.
- draegtun 16y agoThis 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' } };