However, the braces cannot be dropped if the value within the braces
is not a simple scalar variable. For example, for
@{$_[1]} from that last subroutine rewrite, you
can't remove the braces.
This rule also means that it's easy to see where the
"missing" braces need to go. When
you see $$items[1], a pretty noisy piece of
syntax, you can tell that the curly braces must belong around the
simple scalar variable, $items. Therefore,
$items must be a reference to an array.
Thus, an easier-on-the-eyes version of that subroutine might be:
sub check_required_items {
my $who = shift;
my $items = shift;
my @required = qw(preserver sunscreen water_bottle jacket);
for my $item (@required) {
unless (grep $item eq $_, @$items) { # not found in list?
print "$who is missing $item.\n";
}
}
}