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.
is equivalent towhile (<>) { next if /^\s*\#/; # comment next if /^\s*$/; # empty line do_the_work($_); }
while (<>) { if (not /^\s*\#/ and not /^\s*$/) { do_the_work($_); } }
--
[ e d @ h a l l e y . c c ]
In reply to Re: Re: Nested testing of many conditions--a better way?
by halley
in thread Nested testing of many conditions--a better way?
by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |