perl - 如何修复 "Experimental values on scalar is now forbidden"

标签 perl

在 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/

相关文章:

perl - `fast_abs_path` "dangerous, but potentially faster"是什么方式?

linux - 如何防止 Perl 脚本并行运行多次

linux - perl有没有办法运行多个linux命令并在它们之间保存环境变量

regex - 编号的正则表达式捕获的最大数量是多少?

mysql - 如何使用 MYSQL 数据在 perl 脚本中创建键值 JSON 响应

arrays - 获取数组中除第一个以外的所有内容

web-services - SOAP::Lite 是否可用于创建文档/文字 Web 服务?

Perl:使用 REST::Client 模块以编程方式设置 POST 参数

arrays - Perl:你能在 map 函数中使用两个以上的数组吗?

perl - 循环遍历变量以检查是否已定义