in reply to Nested testing of many conditions--a better way?
if ( $today > $start && $today < $stop ) { if ( $today!= $notthisday[0] ) { if ( $today != $notthisday[1] ) { if ( $today != $notthisday[2] ) { if ( $day == $dayofmon[0] || $day == $dayofmon[1] ) { print "$today is the day."; } } } } }
I'd have to kill you if you implemented this in my code base :)
The and-composite is much better and will not draw criticism. By any chance could you put a negated grep in there for the notthisday part to make it a little more Perlish? Also, add some parens rather than relying on your knowledge of the operators as a cautionary technique.
Halley's quick fail routine is one I like a lot, but I think kesterkester's technique may be better for more complex tests, to a C programmer, that's just extra code to read through (IMHO) -- yet allows you to reuse things at the price of method call overhead. But hey, if you are reusing things, you are better off using a really cool well-tested Date module!.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Nested testing of many conditions--a better way?
by bradcathey (Prior) on Mar 23, 2004 at 16:36 UTC |