gpt4 book ai didi

linux - Perl 模块错误 - defined(%hash) 已弃用

转载 作者:IT王子 更新时间:2023-10-29 00:56:54 24 4
gpt4 key购买 nike

背景:

  • 我正在努力将 Linux 服务器从 Ubuntu 10.04 迁移到更新的服务器 12.04
  • 该服务器负责通过 crontabs 执行多个 Perl 模块。
  • 这些 Perl 模块严重依赖 30-40 个 perl 扩展。
  • 我已经安装了所有 Perl 扩展,并且 crontab 能够成功处理,除了这些 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;

关于linux - Perl 模块错误 - defined(%hash) 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34499393/

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