Subject: | Uninitialized value with bind_columns and auto_diag |
If error_diag throws an error from bind_columns, you don't want/need the
noise from an uninitialized value warning to go along with it:
use strict;
use warnings;
use Text::CSV_XS;
my $input = <<EOT;
a,b,c,d
e,f,g,h
EOT
my $r = eval { main() };
unless ($r) {
print "Got an error [$@]\n";
}
sub main {
my @cols = 1..3;
my $csv = Text::CSV_XS->new ({ binary => 1, eol => $/, auto_diag => 2});
my %row; $csv->bind_columns(\@row{@cols});
open(my $fh, "<", \$input) or die "Err: $!";
while ( $csv->getline($fh) ) {
print "Got: ", join("|", @row{@cols}), "\n";
}
return 1;
}
# Output:
Use of uninitialized value in concatenation (.) or string at
.../Text/CSV_XS.pm line 363, <$fh> line 1.
Got an error [# CSV_XS ERROR: 3006 - EHR - bind_columns () did not pass
enough refs for parsed fields @ pos
]