in reply to An idiom for selecting true, false, or undef.
fork is an example where not all cases are equal. undef signals an error condition, while true/false but defined happen equally often. So, I typically write:
Note that the above code doesn't have an else clause. That's intentional.my $pid = fork // die "fork: $!"; unless ($pid) { ... child stuff ... exit; } ... parent stuff ... wait;
In the rare case all three cases are equally important, I might write:
or an if/elsif/else construct. But that's so rare, I can't even remember what I did last time. In the case of wantarray, wantarray being not defined is the exceptional case - if I'm interested in it, I most likely use it for flow control, bypassing expensive calculations.given (EXPR) { when (!defined) {...} when (!$_) {...} default {...} }
|
|---|