0

我正在使用 Chart 模块从 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);
}

但是警告仍然被打印出来。

请问有什么建议吗?

4

2 回答 2

0

通常最好不要忽略警告。

为什么不先处理 undef 值,然后再绘制图表?要么用合理的东西替换它们,要么跳过绘制这些行:

数据.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
于 2013-07-12T07:41:41.880 回答
-1

在您的 Hudson 作业中,为警告信号安装一个处理程序,以过滤警告,这样您所知道的就不会出现。

BEGIN { 
    $SIG{'__WARN__'} = sub { my $w = shift; warn $w if $w !~ m|/Chart/Base.pm| };
}
于 2013-07-11T15:00:29.530 回答