Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Can't understand one line

by Athanasius (Monsignor)
on Jan 07, 2013 at 08:09 UTC ( #1011971=note: print w/ replies, xml ) Need Help??


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,


Comment on Re: Can't understand one line
Select or Download Code
Re^2: Can't understand one line
by anaconda_wly (Scribe) on Jan 07, 2013 at 08:44 UTC
    That' great!Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011971]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2014-09-17 08:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (68 votes), past polls