最近的一个问题使用了sigil不变语法%hash->{key} = 1;进行散列访问,这似乎工作正常,但我认为这将是一个语法错误.
它似乎也适用于数组:
my @array;
@array->[3] = 6;
Run Code Online (Sandbox Code Playgroud)
这种行为是否记录在某处?我不记得读它,但可能忽略了它.
它似乎表现得如下:
(\%hash)->{key}
Run Code Online (Sandbox Code Playgroud)
而不是我会假设的:
(scalar %hash)->{key} # runtime error
Run Code Online (Sandbox Code Playgroud)
似乎这在perlmonks上有所涉及:http://www.perlmonks.org/?node_id = 171177
My reading of perlop has me convinced that this is an unintended syntactic feature. And that's exactly what it is. When using the arrow, Perl will see whatever is left of it as a reference. Including if you have something like @l or %h. Note that you will get the warning Using an array as a reference is deprecated in Perl 5.8.0. Abigail