SPUG: CSV module that can handle multi-line entries?
Dave O
cxreg at pobox.com
Wed Jan 18 22:25:25 PST 2006
On Tue Jan 17 22:03:05 PST 2006, Yitzchak Scott-Thoennes wrote:
> On Tue, Jan 17, 2006 at 04:10:27PM -0800, James Moore wrote:
> > I'm reading Outlook contact books, in what Outlook thinks of as CSV. They
> > look like:
> >
> > "foo","this
> > entry spans two lines"" and has an embedded quote",bar,snark
> >
> > Anyone know of a module that does this? All the CSV parsing I'm finding
> > breaks with multiline quoted entries.
>
> I think Text::CSV_XS may do that.
I can confirm that this is the case, provided you pass the binary => 1
option to new().
Quoth the POD:
binary If this attribute is TRUE, you may use binary characters in
quoted fields, including line feeds, carriage returns and
NUL bytes. (The latter must be escaped as ""0".) By default
this feature is off.
and an example:
perl -MData::Dumper -MText::CSV_XS -e '
my $csv = Text::CSV_XS->new({binary=>1});
$csv->parse(qq^"foo","bar\nbaz",biff^);
print Dumper [$csv->fields]'
$VAR1 = [
'foo',
'bar
baz',
'biff'
];
Dave
More information about the spug-list
mailing list