The first thing to do when you start a script is use strictures:
#!/usr/bin/perl
use strict;
use warnings;
When you finish the script, run it through
Perl::Tidy:
#!/usr/bin/perl -l
use strict;
use warnings;
my (@gilligan) = qw(
red_shirt
hat
lucky_socks
water_bottle
);
check_require_items( 'gilligan', @gilligan );
sub check_require_items {
use strict;
use warnings;
my $who = shift();
my (%whos_items) = map( { $_, 1; } @_ );
my (@required) = qw(
preserver
sunscreen
water_bottle
jacket
);
foreach my $item (@required) {
unless ( $whos_items{$item} ) {
print "$who is missing $item.";
}
}
}
It's easier to read, no?