Subject: | Working with data with embedded newlines |
Date: | Fri, 9 Jan 2009 23:42:30 +0100 |
To: | bug-Text-CSV_XS [...] rt.cpan.org |
From: | Patrick BOURDON <patrick.bourdon [...] bigfoot.com> |
Hello,
I am trying Text::CSV_XS working with data with embedded newlines.
French sep-char is ';'.
I try to give you hereafter my problem context using a on line csv file. Actually, the bug.csv in the exemple has just one "element" including an embedded new line which makes finally a 2 lines file:
Line 1: a;b;c;d;"e
Line 2: f"
I got a "EIQ - Quoted field not terminated" error. So I changed to Text::CSV_PP, and it works (at least as I was expected).
So I suspect there is a bug in CSV_XS::getline. But I may also not be using the module as you may require. Just tell me.
Thanks for the module.
My installation:
- Perl: Active Perl 5.10.0 Build 1004
- OS: Windows XP
Patrick Bourdon - Paris - France
------------------------------------------------------------
use IO::File();
{
use Text::CSV_XS();
my $file = 'bug.csv';
my $fh = IO::File->new("<$file") or die("open(<$file) impossible: ($!)!");
my $csv = Text::CSV_XS->new ({
sep_char => ";",
always_quote => 1,
binary => 1,
allow_whitespace => 1,
verbatim => 1,
});
my $fields = $csv->getline ($fh);
# Dump:
# $csv->error_diag () = [ '2027' 'EIQ - Quoted field not terminated' '12'];
# $csv->error_input() = 'a;b;c;d;"e
#';
# $csv->fields() = undef
}
{
use Text::CSV_PP();
my $file = 'bug.csv';
my $fh = IO::File->new("<$file") or die("open(<$file) impossible: ($!)!");
my $csv = Text::CSV_PP->new ({
sep_char => ";",
always_quote => 1,
binary => 1,
allow_whitespace => 1,
verbatim => 1,
});
my $fields = $csv->getline ($fh);
# Dump:
# $csv->fields() = [ 'a', 'b', 'c', 'd', 'e
# f' ];
}