D
devphylosoff
hey
the first line in one of my subroutine is
shift;
but in this case i cannot use $_ and think $_ = shift;
why ?
entire code:
my @gilligan = qw(a b c d e);
my @skipper = qw(1 2 3 4 5);
my @professor = qw(I II III IV V);
my %all = (
Gilligan => \@gilligan,
Skipper => \@skipper,
Professor => \@professor,
);
sub check_items_for_all {
# $_ = shift; # try this
shift;
for $key (keys %$_) {
check_required_items($key, $_->{$key});
}
}
sub check_required_items {
my $who = shift;
my $items = shift;
my @required = qw(1 2 3 I II III a b c d V);
my @missing = ( );
for my $item (@required) {
unless (grep $item eq $_, @$items) { # not found in list?
print "$who is missing $item.\n";
push @missing, $item;
}
}
if (@missing) {
print "Adding @missing to @$items for $who.\n";
push @$items, @missing;
}
}
the first line in one of my subroutine is
shift;
but in this case i cannot use $_ and think $_ = shift;
why ?
entire code:
my @gilligan = qw(a b c d e);
my @skipper = qw(1 2 3 4 5);
my @professor = qw(I II III IV V);
my %all = (
Gilligan => \@gilligan,
Skipper => \@skipper,
Professor => \@professor,
);
sub check_items_for_all {
# $_ = shift; # try this
shift;
for $key (keys %$_) {
check_required_items($key, $_->{$key});
}
}
sub check_required_items {
my $who = shift;
my $items = shift;
my @required = qw(1 2 3 I II III a b c d V);
my @missing = ( );
for my $item (@required) {
unless (grep $item eq $_, @$items) { # not found in list?
print "$who is missing $item.\n";
push @missing, $item;
}
}
if (@missing) {
print "Adding @missing to @$items for $who.\n";
push @$items, @missing;
}
}