Subject: | Working with data with embedded sep_char and escape_char |
Date: | Sat, 10 Jan 2009 01:11:00 +0100 |
To: | bug-Text-CSV [...] rt.cpan.org |
From: | Patrick BOURDON <patrick.bourdon [...] bigfoot.com> |
Hello,
I am trying Text::CSV_PP working with data with embedded sep_char and escape_char.
Note that French sep_char is ';'.
I present hereafter a simple and complete small piece of code including the problem I encountered.
I am unclear about the fact it is a bug or a misusage.
Thanks for the module.
My installation:
- Perl: Active Perl 5.10.0 Build 1004
- OS: Windows XP
- Module: Text-CSV 1.10 (31/10/2008)
Patrick Bourdon - Paris - France
----------------------------------------------------
{
use Text::CSV_PP();
my $csv = Text::CSV_PP->new ({
sep_char => ";",
always_quote => 1,
binary => 1,
allow_whitespace => 1,
verbatim => 1,
});
# First test:
{
my $line = '20/10/2008;Le LHC;chaines;Le LHC;"Le des ""hadrons"" au CNRS ; Michel CNRS/INP2P3"';
my $status = $csv->parse ($line);
# CORRECT: I got the expected result (dump):
#
# $csv->fields() = [
# '20/10/2008',
# 'Le LHC',
# 'chaines',
# 'Le LHC',
# 'Le des "hadrons" au CNRS ; Michel CNRS/INP2P3'
# ];
#
}
# Second test:
{
use IO::File();
my $file = 'bug1.csv';
# bug1.csv includes the same text in first line together with a second line is empty
# Line 1: 20/10/2008;Le LHC;chaines;Le LHC;"Le des ""hadrons"" au CNRS ; Michel CNRS/INP2P3"
# Line 2:
my $fh = IO::File->new("<$file") or die("open(<$file) impossible: ($!)!");
my $fields = $csv->getline ($fh);
# I got the following ERROR:
#
# $csv->error_diag () = [
# 2027,
# 'EIQ - Quoted field not terminated',
# 56
# ];
# $csv->error_input() = '20/10/2008;Le LHC;chaines;Le LHC;"Le des ""hadrons"" au CNRS ; Michel CNRS/INP2P3"
#';
# $csv->fields() = [ undef ];
}
}