in reply to Re: Nested testing of many conditions--a better way?
in thread Nested testing of many conditions--a better way?

Agreed. The cascade of tests with and is preferable to my eye.

Just a note that there is a difference between and vs &&. The difference is order of precedence. BrowserUK used the word form so that he didn't have to worry about order of precedence so much. You can also use parentheses with either form to ensure the precedence is correct. The original example is in danger of accidentally mixing up precedence, and getting a completely wrong result.

A third alternative, in some cases, is the "quick fail." This is a series of reasons to break out of a loop or return from a subroutine early.

while (<>) { next if /^\s*\#/; # comment next if /^\s*$/; # empty line do_the_work($_); }
is equivalent to
while (<>) { if (not /^\s*\#/ and not /^\s*$/) { do_the_work($_); } }

--
[ e d @ h a l l e y . c c ]