Perl模块错误-已定义(%hash)已弃用 [英] Perl Module Error - defined(%hash) is deprecated

查看:200
本文介绍了Perl模块错误-已定义(%hash)已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

  • 我正在努力将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};
    }
    ###

希望有人可以提供帮助,感谢您的帮助.

Hopefully someone can help with this, any help is appreciated.

推荐答案

您必须已从Perl的较旧版本升级. Perl 5.6.1发行说明说:

You must have upgraded from a seriously old version of Perl. The Perl 5.6.1 release notes say:

已弃用已定义的(%hash)

defined(%hash) is deprecated

(D)define()通常在散列上不有用,因为它会检查是否存在 未定义的标量值.如果您想查看哈希是否为空,只需 例如使用if (%hash) { # not empty }.

(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警告您您做的事情很愚蠢.警告很明显,您应该如何解决此问题:

It was always a pretty stupid thing to do and Perl now warns you that you're doing something stupid. The warning is pretty clear about what you should do to fix this:

也许您应该只忽略define()?

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;

这篇关于Perl模块错误-已定义(%hash)已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆