gpt4 book ai didi

perl - 推送到取消引用的数组上会发出警告

转载 作者:行者123 更新时间:2023-12-04 17:34:11 24 4
gpt4 key购买 nike

我有代码:

push @$args{"ARRAY"}, "value";

这给出了警告说:
push on reference is experimental at ...

如果我只是在数组周围使用块:
push @{args{"ARRAY"}}, "value";

然后警告消失。为什么会这样?

最佳答案

@$args{"ARRAY"}相当于 @{$args}{"ARRAY"} ,不是 @{$args{"ARRAY"}} .来自 perlref , section "Using References" :

Because of being able to omit the curlies for the simple case of $$x, people often make the mistake of viewing the dereferencing symbols as proper operators, and wonder about their precedence. If they were, though, you could use parentheses instead of braces. That's not the case. Consider the difference below; case 0 is a short-hand version of case 1, not case 2:

   $$hashref{"KEY"}   = "VALUE";       # CASE 0
${$hashref}{"KEY"} = "VALUE"; # CASE 1
${$hashref{"KEY"}} = "VALUE"; # CASE 2
${$hashref->{"KEY"}} = "VALUE"; # CASE 3

关于perl - 推送到取消引用的数组上会发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29190848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com