【发布时间】:2016-04-02 15:35:12
【问题描述】:
背景:
- 我正在努力将 Linux 服务器从 Ubuntu 10.04 迁移到较新的服务器到 12.04
- 此服务器负责通过 crontab 执行多个 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 并没有引起错误,它们只是向您展示了它们的存在。这也是一个非致命警告,而不是语法错误。我认为重点是检查哈希是否为空,在这种情况下,您可以使用
unless %hash。就像这个答案所示:stackoverflow.com/questions/9444915/…
标签: linux perl hash crontab perl-module