背景:
我正在努力将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发行说明说:
不推荐使用defined(%hash)
(D)defined()通常对哈希值没用,因为它会检查未定义的标量值.如果你想查看散列是否为空,只需使用
if (%hash) { # not empty }
例如.
这总是一件非常愚蠢的事情,Perl现在警告你,你做的事情很愚蠢.关于你应该做些什么来解决这个问题的警告非常明确:
也许你应该省略define()?
所以你的线将成为:
die("Error: NULL CMS counts for symbol '$symbol'") unless %cms_row; die("Error: NULL Stats counts for symbol '$symbol'") unless %stats_row;