What does @_ mean at the beginning of code in Perl?
A::(tmp:7): our $_ = 1;
DB<9> V :: _
@_ = (
0 0
1 '_'
2 *main::_
3 0
4 '-1'
)
DB<10>
The above is the output of V :: _
at the 1开发者_C百科st line of code,what does @_
mean?
@_
is the variable that holds a subroutine's parameters.
When you look at it with V in the debugger, it seems to show the parameters for some internal-to-the-debugger subroutine.
The latest versions of perldoc let you look up variables with the -v
switch, which extracts just the part you need from perlvar:
$ perldoc -v '@_'
@ARG
@_ Within a subroutine the array @_ contains the parameters passed
to that subroutine. See perlsub.
http://perldoc.perl.org/perlvar.html#General-Variables
Within a subroutine the array @_ contains the parameters passed to that subroutine. Inside a subroutine, @_ is the default array for the array operators push, pop, shift, and unshift
In essence, @_
is the array equivalent of $_
use Data::Dumper;
foo(0,'_',*main::_,0,-1);
sub foo {
print Dumper(\@_);
}
Outputs:
$VAR1 = [
0,
'_',
*::_,
0,
-1
];
精彩评论