运维开发网

在Linux中Perl模块错误 – 已定义(%hash)已弃用

运维开发网 https://www.qedev.com 2020-07-07 08:56 出处:网络
背景: >我正在努力将Linux服务器迁移到Ubuntu 10.04到12.04的新服务器>该服务器负责通过crontabs执行多个Perl模块.>这些Perl模块严重依赖30-40 perl扩展.>我已经安装了所有Perl扩展,并且crontabs能够
背景:

>我正在努力将Linux服务器迁移到Ubuntu 10.04到12.04的新服务器

>该服务器负责通过crontabs执行多个Perl模块.

>这些Perl模块严重依赖30-40 perl扩展.

>我已经安装了所有Perl扩展,并且crontabs能够成功处理,除了由这些Perl扩展的较新版本引起的几个语法错误.

>我需要一些帮助来修改语法以使Perl脚本按预期进行处理.

错误:

defined(%hash) is deprecated at pm/Alerts/Alerts.pm line 943.
        (Maybe you should just omit the defined()?)
defined(%hash) is deprecated at pm/Alerts/Alerts.pm line 944.
        (Maybe you should just omit the defined()?)

码:

###
    # Iterate the arrays deleting identical counts from each.
    # If we found a mismatch then die.
    # If either array is not empty when we are done then die
    $logger->info('Comparing ' . (scalar keys %cms_rows) . ' CMS symbols to ' . (scalar keys %stats_rows) . ' STATS symbols');

    foreach my $symbol ( keys %cms_rows ) {
    my %cms_row = delete $cms_rows{$symbol};
    my %stats_row = delete $stats_rows{$symbol};

##LINE 943##    die("Error: NULL CMS counts for symbol '$symbol'") unless defined %cms_row;
##LINE 944##    die("Error: NULL Stats counts for symbol '$symbol'") unless defined %stats_row;

    my $cms_json = encode_json(\%cms_row);
    my $stats_json = encode_json(\%stats_row);
    $logger->debug("Comparing counts for '$symbol': CMS($cms_json), Stats($stats_json)");

    die("Error: Up Counts Don't match for symbol '$symbol': CMS($cms_json), Stats($stats_json)") unless (!defined $cms_row{1} && !defined $stats_row{1}) || $cms_row{1} == $stats_row{1};
    die("Error: Down Counts Don't match for symbol '$symbol': CMS($cms_json), Stats($stats_json)") unless (!defined $cms_row{-1} && !defined $stats_row{-1}) || $cms_row{-1} == $stats_row{-1};
    }
    ###

希望有人可以提供帮助,任何帮助都表示赞赏.

您必须从严重旧版本的Perl升级. Perl 5.6.1 release notes说:

defined(%hash) is deprecated

(D) defined() is not usually useful on hashes because it checks for an

undefined scalar value. If you want to see if the hash is empty, just

use if (%hash) { # not empty } for example.

这总是一件非常愚蠢的事情,Perl现在警告你,你做的事情很愚蠢.关于你应该做些什么来解决这个问题的警告非常明确:

Maybe you should just omit the defined()?

所以你的线将成为:

die("Error: NULL CMS counts for symbol '$symbol'") unless %cms_row;
die("Error: NULL Stats counts for symbol '$symbol'") unless %stats_row;
0

精彩评论

暂无评论...
验证码 换一张
取 消