Perl中@_的含义是什么? [英] What is the meaning of @_ in Perl?
问题描述
@_
在 Perl 中是什么意思?
What is the meaning of @_
in Perl?
推荐答案
perldoc perlvar 是检查任何特殊命名的 Perl 变量信息的第一个地方.
perldoc perlvar is the first place to check for any special-named Perl variable info.
引用:
@_
:在子例程中,数组 @_
包含传递给该子例程的参数.
@_
: Within a subroutine the array@_
contains the parameters passed to that subroutine.
可以在从 perlvar 链接的 perldoc perlsub(Perl 子例程) 中找到更多详细信息:
More details can be found in perldoc perlsub (Perl subroutines) linked from the perlvar:
传入的任何参数都显示在数组 @_
.
Any arguments passed in show up in the array
@_
.
因此,如果你调用一个带有两个参数的函数,那些将存储在 $_[0]
和 $_[1]
中.
Therefore, if you called a function with two arguments, those
would be stored in $_[0]
and $_[1]
.
数组@_
是一个本地数组,但它的元素是实际标量参数的别名.特别地,如果一个元素 $_[0] 被更新,相应的参数被更新(或如果不是,则会发生错误可更新).
The array @_
is a local array, but its
elements are aliases for the actual scalar parameters.
In particular, if
an element $_[0] is updated, the
corresponding argument is updated (or
an error occurs if it is not
updatable).
如果一个参数是一个数组或不存在的散列元素当函数被调用时,元素仅在(和如果)时创建它被修改或对它的引用是采取.(一些早期版本的 Perl无论是否创建元素元素被分配给.)分配给整个数组@_ 删除了别名,并且不更新任何参数.
If an argument is an array or hash element which did not exist when the function was called, that element is created only when (and if) it is modified or a reference to it is taken. (Some earlier versions of Perl created the element whether or not the element was assigned to.) Assigning to the whole array @_ removes that aliasing, and does not update any arguments.
这篇关于Perl中@_的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!