note
eyepopslikeamosquito
<P>Yes, I agree.
I especially like that there is only one <C>return</C> statement.
In contrast, using multiple <C>return</C> statements violates the principle of
<a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a>.
</P>
<P>
Related items from Conway's <a href="https://www.squirrel.nl/pub/PBP_refguide-1.02.00.pdf">Perl Best Practices</a>,
Chapter 6 (Control Structures):
<ul>
<li> Avoid cascading an <C>if</C>
<li> Use table look-up in preference to cascaded equality tests
<li> When producing a value, use tabular ternaries
</ul>
</P>
<P>
Conway recommends formatting tabular ternaries with the colon at the front,
for example:
<CODE>
# When their name is... Address them as...
my $salute = $name eq $EMPTY_STR ? 'Customer'
: $name =~ m/(.*), \s+ Ph[.]?D \z /xms ? "Dr $1"
: $name
;
</CODE>
because, if you squint, it looks like a lookup table,
thus converting the notoriously impenetrable ternary syntax
into a familiar and easy to understand lookup table.
</P>
<P>
<B>Update:</B> Fixed typo in Conway's example <C>my $salute</C> statement above (removed extra <C>?</C>). Thanks [AnomalousMonk].
</P>
11124000
11124183