我使用图表模块从CSV数据生成PNG格式的图表:
效果很好,图表看起来还不错,但我收到了undef
值的警告(上图中末尾有3个这样的值):
# ~/txv3.pl "./L*TXV3*.csv" > /var/www/html/x.html
Generating chart: L_B17_C0_TXV3LIN_PA3_TI1_CI1
Use of uninitialized value $label in length at /usr/share/perl5/vendor_perl/Chart/Base.pm line 3477, <> line 69.
Use of uninitialized value in subroutine entry at /usr/share/perl5/vendor_perl/Chart/Base.pm line 3478, <> line 69.
Use of uninitialized value $label in length at /usr/share/perl5/vendor_perl/Chart/Base.pm line 3477, <> line 69.
Use of uninitialized value in subroutine entry at /usr/share/perl5/vendor_perl/Chart/Base.pm line 3478, <> line 69.
Use of uninitialized value $label in length at /usr/share/perl5/vendor_perl/Chart/Base.pm line 3477, <> line 69.
Use of uninitialized value in subroutine entry at /usr/share/perl5/vendor_perl/Chart/Base.pm line 3478, <> line 69.
我需要摆脱这些警告,因为它们在这里没用,它们使我的Hudson工作日志变得难以理解。
所以我尝试过(在CentOS 6.4 / 64位上使用perl 5.10.1):
#!/usr/bin/perl -w
use strict;
....
$pwrPng->set(%pwrOptions);
$biasPng->set(%biasOptions);
my $pwrPngFile = File::Spec->catfile(PNG_DIR, "${csv}_PWR.png");
my $biasPngFile = File::Spec->catfile(PNG_DIR, "${csv}_BIAS.png");
{
no warnings;
$pwrPng->png($pwrPngFile, $pwrData);
$biasPng->png($biasPngFile, $biasData);
}
但警告仍然打印出来。
有什么建议吗?
答案 0 :(得分:0)
通常最好不要忽略警告。
为什么不在绘制图表之前先处理undef值? 要么用合理的东西替换它们,要么跳过绘制那些行:
data.csv
RGI,BIAS,LABEL
20,130,"1146346307 #20"
21,135,"1146346307 #21"
22,140,
-
use Scalar::Util qw( looks_like_number );
my $fname = "data.csv";
open $fh, "<$fname"
or die "Unable to open $fname : $!";
my $data = [];
while (<$fh>) {
chomp;
my ($rgi, $bias, $label) = split /,/; # Better to use Text::CSV
next unless looks_like_number($rgi);
next unless looks_like_number($bias);
$label ||= "Unknown Row $."; # Rownum
# Create whatever structure you need.
push @$data, { rgi => $rgi, bias => $bias, label => $label };
}
# Now draw chart
答案 1 :(得分:-1)
在你的Hudson作业中,为warn信号安装一个处理程序,用于过滤警告,以便你知道的那些不会出现。
BEGIN {
$SIG{'__WARN__'} = sub { my $w = shift; warn $w if $w !~ m|/Chart/Base.pm| };
}