我看到了一些像这样的代码〜
my @array = @{ $array_ref };
Run Code Online (Sandbox Code Playgroud)
我发现如果我把它改成〜它的工作原理是一样的
my @array = @$array_ref;
Run Code Online (Sandbox Code Playgroud)
同样,这个〜
my %hash = (frogs => sub {print "Frogs\n"});
&{$hash{frogs}}();
Run Code Online (Sandbox Code Playgroud)
与〜一样工作
%hash = (frogs => sub {print "Frogs\n"});
$hash{frogs}();
Run Code Online (Sandbox Code Playgroud)
(虽然我最初尝试过,因为&hash{frogs}();期望它能够工作,但由于产生的错误我不明白 - 这个sigil是否应该与哈希中访问的东西相对应,在这种情况下&对于子程序?)
所以我想知道为什么这些片段的作者会以另一种方式编写它们,当它是额外的字符而没有我能感知到的任何优势时.
在这里发生的事情我没有注意到吗?什么时候你可能需要使用花括号而不仅仅是sigil?
perl ×1