在 Perl 5.26.1 中我得到:
Experimental values on scalar is now forbidden at /funcx.pm line 110.
其中第110行是foreach in
sub checkSsh {
foreach my $slave (values $::c{slaves}) {
...
}
}
$c
包含
$VAR1 = {
'slaves' => {
'48' => '10.10.10.48'
},
};
在哪里
our %c = %{YAML::Syck::LoadFile($config)};
问题
究竟是什么问题?应该如何修复?
最佳答案
Perl 提示你正在调用 values
建立在一个 SCALAR 上,在本例中是一个 HASHREF:
正确取消引用您的 slaves
键允许 values
按预期工作:
foreach my $slave ( values %{ $c{slaves} } ) {
...
}
至于您收到的具体警告,他们直接在 perldoc 页面中解决了这个问题:
Starting with Perl 5.14, an experimental feature allowed values to take a scalar expression. This experiment has been deemed unsuccessful, and was removed as of Perl 5.24.
To avoid confusing would-be users of your code who are running earlier versions of Perl with mysterious syntax errors, put this sort of thing at the top of your file to signal that your code will work only on Perls of a recent vintage:
use 5.012; # so keys/values/each work on arrays
关于perl - 如何修复 "Experimental values on scalar is now forbidden",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49922419/