note
jettero
If bar() is a complex function, then perhaps it should be the one returning the default value...
<p> If that's not reasonable, then perhaps you need a default wrapper or something... Here's two ideas:
<code>
sub mybar {
my $t = bar();
return "default" unless defined $t;
return $t;
}
sub default {
my $to_call = shift;
my $default = shift;
my $t = to_call->(@_);
return $default unless defined $t;
return $t;
}
</code>
<p> Or just do what the others said above (5.10+ only): <c>$x = bar() // "default";</c>
<div class="pmsig"><div class="pmsig-16186">
<p>-Paul</p>
</div></div>
818418
818418