* Ed Avis <perlbug-followup@perl.org> [2016-07-20 15:48]: > I don't know about you, but I find my code full of checks like this: > > foreach my $i (@items) { > die "seen $_ twice" if defined $score{$i}; > $score{$i} = get_score($i); > } > > (Here 'exists' could be more appropriate than 'defined' if the score > itself can be undef, but for the scope of this discussion I am > considering definedness.) > > Or perhaps they can be written in a more 'topical' way as > > foreach my $i (@items) { > for ($score{$i}) { > die if defined; > $_ = get_score($i); > } > } You don’t need a new language feature. sub ensure_undef ($) : lvalue { defined $_[0] ? croak 'Unexpected defined value' : $_[0] } foreach my $i (@items) { ensure_undef $score{$i} = get_score($i); } Regards, -- Aristotle Pagaltzis // <http://plasmasturm.org/>Thread Previous | Thread Next