I'd recommend a refinement of your second technique-- use a single if statement, but break up your conditions into small subroutines with descriptive names.
if ( date_in_range ( $today, $start, $stop ) &&
date_not_bad ( $today, @notthisday ) &&
good_day_of_month ( $day, @dayofmon )
{
print "$today is the day";
}
sub date_in_range {
my ( $today, $start, $stop ) = @_;
return $today > $start && $today < $stop;
}
sub date_not_bad {
my ( $today, @notthisday ) = @_;
return $today != $notthisday[0] &&
$today != $notthisday[1] &&
$today != $notthisday[2];
}
sub good_day_of_month ( $day, @dayofmon ) {
my ( $day, @dayofmon ) = @_;
return $day == $dayofmon[0] ||
$day == $dayofmon[1];
}
Untested code, but that gets the idea across.
Chapters 12 and 14 of Code Complete also talk about various fun methods of optimizing if blocks.
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.