In your Hudson-job, install a handler for the warn signal that filters warnings so the ones you know about won't show up.
BEGIN {
$SIG{'__WARN__'} = sub { my $w = shift; warn $w if $w !~ m|/Chart/Base.pm| };
}
문제
I'm using Chart module to generate charts in PNG format from CSV data:
It works well, the charts look okay, but I get warnings for the undef
values (there are 3 such values at the end of the above diagram):
# ~/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.
I need to get rid of these warnings as they are useless here and they make the log of my Hudson-job unreadable.
So I've tried (using perl 5.10.1 on CentOS 6.4 / 64 bit):
#!/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);
}
But the warnings are still printed.
Any suggestions please?
해결책 2
In your Hudson-job, install a handler for the warn signal that filters warnings so the ones you know about won't show up.
BEGIN {
$SIG{'__WARN__'} = sub { my $w = shift; warn $w if $w !~ m|/Chart/Base.pm| };
}
다른 팁
Usually it is best not to ignore warnings.
Why don't you just handle the undef values first, before charting? Either replace them with something sensible, or skip plotting those rows:
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