what "shift" does, if not "$_ = shift;" ?



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;
}
}
.



Relevant Pages

  • Re: $# array creation and data rotation
    ... ,, now, as data comes in via the serial port ... ,, first want to "shift" the data: ... ,, and then push the new data: ... an array, or adding an element to an array. ...
    (comp.lang.perl.misc)
  • Re: Joining/Merging AoA
    ... push my @c, [@{shift @a}]; ... perldoc -f shift ... better off starting a new thread on understanding references. ...
    (perl.beginners)
  • Re: simplify a path
    ... sub canonical_path { ... my $path = shift; ... push @tests, qw( ... empty directory names can be returned, ...
    (perl.beginners)
  • Re: [PATCH]: tick-sched.c build fix
    ... I'll push the two bug fixes I ... Nobody writing these timer drivers ... function figured out an appropriate shift and multiplier to use. ... BTW, that's how I hit the Niagara shift issue, divide by zero ...
    (Linux-Kernel)
  • Re: difference between "@_" and "shift"
    ... shift is a function for pulling off the first element from a list. ... You can push to and pop from the end ... of lists to treat them as stacks; you can shift from and unshift to the ...
    (perl.beginners)