what "shift" does, if not "$_ = shift;" ?
- From: devphylosoff <devphyl@xxxxxxxxx>
- Date: Thu, 29 Nov 2007 10:25:24 -0800 (PST)
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;
}
}
.
- Follow-Ups:
- Re: what "shift" does, if not "$_ = shift;" ?
- From: Peter Makholm
- Re: what "shift" does, if not "$_ = shift;" ?
- Prev by Date: Re: How to persist and query a hash lookup in memory with Perl ?
- Next by Date: Errors using installing perl modules
- Previous by thread: FAQ 4.67 Why does passing a subroutine an undefined element in a hash create it?
- Next by thread: Re: what "shift" does, if not "$_ = shift;" ?
- Index(es):
Relevant Pages
|