in reply to Can't understand one line
shift(@_) is a current $_
No. Here is the skeleton of the opening of the import subroutine in Win32::TieRegistry:
sub import { my $pkg = shift(@_); ... local( $_ ); while( @_ ) { $_= shift(@_); if( ... ) { ... } elsif( ... ) { ... ... } elsif( exists $_opt_subs{$_} ) { ... $registry->$_( shift(@_) ); } elsif( ... ) { ...
Each call to shift removes another element from the head of the @_ array, i.e., another argument from the list of those passed into sub import. So in the line:
$registry->$_( shift(@_) );
the variable $_ holds the last argument to have been removed from @_; but the expression shift(@_) removes the next argument from @_. $_ and shift(@_) will (most likely) have different values.
shift(@_) does not reset the value of $_:
17:43 >perl -wE "f(1, 2, 3); sub f { local($_) = shift(@_); my $c = sh +ift(@_); say '$_ = ', $_; say '$c = ', $c; say '@_ = ', @_; }" $_ = 1 $c = 2 @_ = 3 18:07 >
Hope that helps,
Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Can't understand one line
by anaconda_wly (Scribe) on Jan 07, 2013 at 08:44 UTC |
In Section
Seekers of Perl Wisdom