Chapter 4 Learning Perl (6th Edition) has a section called Arguments . It says the following:
This means that the first parameter of the subroutine is in $_[0] , the second is stored in $_[1] , etc. But - and here's an important note - these variables have nothing to do with $_ , no more than $dino[3] (the @dino element of the array) has to do with $dino (a completely different scalar variable). It's just that the parameter list needs to be in some array variable for your routine to use it, and Perl uses @_ for this purpose.
( Exploring Perl, 6th Edition, Chapter 4 )
Thus, you are probably mistaken when using $_ , when you should either use my $name = $_[0]; , or my $name = shift @_; . For convenience, when you are inside a subroutine, shift by default switches from @_ if you did not specify an explicit argument, so the general idiom should say my $name = shift; .
For those who need another resource, perldoc perlintro also has a good (and accordingly short) explanation of passing parameters to subprograms and accessing them via @_ or shift .
Here is a short excerpt from perlintro :
What is this shift ? Well, there are arguments in the subroutine for us as a special array called @_ (for more details, see perlvar ). the default argument to the shift function is simply @_ . So my $logmessage = shift; shifts the first item from the argument list and assigns it to $logmessage .
source share