想着下一个。有一个清单
qw(a b c);
现在,将 LIST 分配给无名(匿名)数组
[ qw(a b c) ]
所以接下来
use 5.016;
use warnings;
use diagnostics;
my $x = [ qw(a b c) ];
say ref $x; #ARRAY - the $x is an ARRAY reference, and
say $x->[1]; #prints "b", and
say [ qw(a b c) ]->[1]; #works too
但现在会发生什么?
use 5.016;
use warnings 'all';
use diagnostics;
say ${[ qw(a b c) ]}[1];
它打印b
,但是
my $y = ${[ qw(a b c) ]};
是一个错误,
Not a SCALAR reference at pepe line 6 (#1)
(F) Perl was trying to evaluate a reference to a scalar value, but found
a reference to something else instead. You can use the ref() function
to find out what kind of ref it really was. See perlref.
Uncaught exception from user code:
Not a SCALAR reference at pepe line 17.
那么,构造 ${.... } 是什么意思
- 它在
say
(打印匿名数组的第二个元素)中“工作”,但不明白为什么 - 但不能将其分配给变量
并且来自的提示diagnostics
不是很有帮助,因为ref
当我无法分配时我应该如何使用?我错过了perlref
什么?