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,
|