- #!/usr/bin/perl -w
-
#
-
use strict;
-
-
my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
-
check_required_items('The Skipper', \@skipper);
-
print "@skipper\n";
-
sub check_required_items{
-
my $who = shift;
-
my $items = shift;
-
my @required = qw(preserver sunscreen water_bottle jacket);
-
my @missing=();
-
-
foreach my $item (@required){
-
unless( grep $item eq $_, @$items){
-
print "$who missing $item\n";
-
push @missing, $item;
-
}
-
}
-
if (@missing){
-
push @$items, @missing;
-
}
-
}
#The Skipper missing water_bottle
#blue_shirt hat jacket preserver sunscreen water_bottle
here we insert the missing items to the orignal array. if dont use the reference, the change will be not affected the orignal array.