When the value in the first column of the first row of a CSV file is
quoted, Text::CSV (both _XS and _PP) fails to parse the line, error_diag
is "2034EIF - Loose unescaped quote4".
See the attached test script and test CSV file for an example.
The output when running the script with the test file is:
2034EIF - Loose unescaped quote4 at csvtest.pl line 29, <GEN0> line 1.
Enabling the allow_loose_quotes option stops the script from crashing,
but the resulting value isn't correct:
"foo"|bar|baz
instead of
foo|bar|baz
With the quotes removed from the first value (so the input is:
foo;"bar";"baz"), the output is correct:
foo|bar|baz
Tested with the latest versions of Text::CSV (1.21), Text::CSV_XS (0.81)
and Text::CSV_PP (1.29).
Subject: | test.csv |
"foo";"bar";"baz"
Subject: | csvtest.pl |
#!/usr/bin/env perl
use strict;
use warnings;
use Text::CSV_XS;
use IO::File;
die "Usage: $0 <file>\n" if(@ARGV != 1);
my ($file) = @ARGV;
my $fh = new IO::File($file) or die "Can't open $file. $!.\n";
my $csv = new Text::CSV_XS(
{
sep_char => ';',
quote_char => '"',
escape_char => '"',
binary => 1,
eol => "\n",
# allow_loose_quotes => 1,
}
);
until($fh->eof) {
my $row = $csv->getline($fh);
die $csv->error_diag unless $row;
print join('|', @$row), "\n";
}