3 # Using the final version of check_required_items, write a subroutine
4 # check_items_for_all that takes as its only parameter a reference to a
5 # hash whose keys are the people aboard the Minnow and whose corresponding
6 # values are array references of the things they intend to bring on board.
8 # For example, the hash reference might be constructed like so:
10 # my @gilligan = (... gilligan items ...);
11 # my @skipper = (... skipper items ...);
12 # my @professor = (... professor items ...);
15 # Gilligan => \@gilligan,
16 # Skipper => \@skipper,
17 # Professor => \@professor,
20 # check_items_for_all(\%all);
22 # The newly constructed subroutine should call check_required_items for
23 # each person in the hash, updating their provisions list to include the
26 # Some starting code is in the Downloads section on
27 # https://www.intermediateperl.com/
34 sub check_required_items {
37 my %whose_items = map { $_, 1 } @$items;
38 my @required = qw(preserver sunscreen water_bottle jacket);
41 for my $item (@required) {
42 unless ($whose_items{$item}) {
43 print "$who is missing $item.\n";
49 print "Adding @missing to @$items for $who.\n";
50 push @$items, @missing;
53 sub check_items_for_all {
55 foreach my $person (keys %$allref) {
56 check_required_items($person, $allref->{$person});
59 my @gilligan = qw(red_shirt hat lucky_socks water_bottle);
60 my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
61 my @professor = qw(sunscreen water_bottle slide_rule batteries radio);
64 Gilligan => \@gilligan,
66 Professor => \@professor,
69 check_items_for_all(\%all);