I am familiar with assigning a match to a variable using list context:
my ($ans) = $somevar =~ m/(somestuff)/;
But what if I want to assign a default value to $ans when the match fails? Is there a way to do this well in one expression? Preferably without a conditional operator?
Perhaps the ternary operator will be helpful:
my $ans = $somevar =~ /(somestuff)/ ? $1 : 'default_val';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With