L
Lars Haugseth
* Lawrence Statton said:Yeah -- I like your bridesmaid code better, too ... I'm still trying
to think of a good example before breakfast. I need caffeine and
sugar and lipids to write ...
I prefer the 'next' method when there are several conditions that could
cause a list item to be skipped (without generating an exception of any
kind):
for my $item (@list) {
next if ($item->{'Foo'} < 0);
next if (!defined $item->{'Bar'});
next if ($item->{'Baz'} eq 'IGNORE');
<do stuff with $item>
}
I like the above better than the following:
for my $item (@list) {
if ($item->{'Foo'} >= 0 &&
defined $item->{'Bar'} &&
$item->{'Baz'} ne 'IGNORE')
{
<do stuff with $item>
}
}
...especially when the conditionals are complex and/or hard to read,
and there are many of them.
There's also the added bonus of getting one less level of indentation.
In addition, it makes it pretty clear up front that these are special
cases and not the norm.