是什么 ->箭头在 Perl 中做什么? [英] What does the -> arrow do in Perl?
问题描述
我一直在代码中看到 ->
,但我不确定它的含义.例如:
I keep seeing ->
in code and I am not exactly sure what it means. For example:
@top_links = @{$m->links};
这条线有什么作用?另外,我可以在哪里阅读有关它的信息?
What does this line do? Also, where can I maybe read about it?
推荐答案
参见 perlop 中的箭头运算符:
"->
"是一个中缀解引用运算符,就像在 C 和 C++ 中一样.如果右侧是 [...]
、{...}
或 (...)
下标,则左侧必须分别是对数组、散列或子程序的硬引用或符号引用.(或者从技术上讲,一个能够保存硬引用的位置,如果它是用于赋值的数组或散列引用.)参见 perlreftut 和 perlref.
"
->
" is an infix dereference operator, just as it is in C and C++. If the right side is either a[...]
,{...}
, or a(...)
subscript, then the left side must be either a hard or symbolic reference to an array, a hash, or a subroutine respectively. (Or technically speaking, a location capable of holding a hard reference, if it's an array or hash reference being used for assignment.) See perlreftut and perlref.
否则,右侧是方法名或包含方法名或子例程引用的简单标量变量,左侧必须是对象(受祝福的引用)或类名(即包裹名字).请参阅 perlobj.
Otherwise, the right side is a method name or a simple scalar variable containing either the method name or a subroutine reference, and the left side must be either an object (a blessed reference) or a class name (that is, a package name). See perlobj.
这篇关于是什么 ->箭头在 Perl 中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!