I would write that, clearly and efficiently I hope, using a low priority short-circuiting boolean operator: my $total = grep { defined ( $_->value ) and $_->value > $limit } @things; no reason to abuse the ternary op like that. On Sat, Dec 18, 2021 at 5:09 AM Ovid via perl5-porters < perl5-porters@perl.org> wrote: > > I, for one, am tired of writing code like this: > > my $total = grep { defined $_->value ? $_->value > $limit : 0 } > @things; > > Note: the following is *not* equivalent to the above: > > my $total = grep { ( $_->value // 0 ) > $limit } @things; > > I mean, it *looks* correct, but what if the value can be a negative number > and the limit can be negative? You probably than want this: > > my $total = grep { ( $_->value // ( $limit - 1 ) ) > $limit } @things; > > Which arguably might be more confusing than using defined. With 3VL, we > have this: > > my $total = grep { $_->resolution < $limit } @things; > > Worse, I'm tired of tracking down bugs caused by this. > -- "Lay off that whiskey, and let that cocaine be!" -- Johnny CashThread Previous | Thread Next