I seldomly need an idiom to distinguish between all three - in most cases, I'm either interested in "true or false" or "defined or not defined". In the rare cases, the idiom I use depends whether I consider all cases equal or not.
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:
my $pid = fork // die "fork: $!";
unless ($pid) {
... child stuff ...
exit;
}
... parent stuff ...
wait;
Note that the above code doesn't have an else clause. That's intentional.
In the rare case all three cases are equally important, I might write:
given (EXPR) {
when (!defined) {...}
when (!$_) {...}
default {...}
}
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.