http://www.perlmonks.org?node_id=617889


in reply to The future of Text::CSV_XS - TODO

Hi,

I think that making the eol option actually honour $/ would be extremely useful, and I think your suggested API for that would work fine. As I understand it (and the current behaviour of Text::CSV_XS certainly seems to bear me out) the module only handles \015\012 and \012 as CSV line endings for parsing input. It would be tremendously helpful if \015 was also supported. I'm assuming it's not, since I've never been able to get it to work despite occasional attempts over the years. There's also a note in the POD (CAVEATS) suggesting that alternate line endings are unsupported. I'm often surprised at the number of people out there still using spreadsheet software that generates CSV files with \015 line endings. I think older Mac OS machines, and some ill-behaved Mac OSX applications are at fault (if fault it really is).

Cheers,

Tim

Update: based on the principle that every bug report should at least take a stab at giving a test case, here's what I'm talking about:

perl -MText::CSV_XS -MIO::File -e '$/="\r"; $f = IO::File->new_tmpfile +; print $f "a,b,c$/"; seek($f,0,0); $c = Text::CSV_XS->new({eol => $/ +}); print join("|",@{ $c->getline($f) })'
That should output "a|b|c", and indeed does if $/ is set to \n or \r\n. Just clearing up any possible misunderstandings :-)

Replies are listed 'Best First'.
Re^2: The future of Text::CSV_XS - TODO
by Tux (Canon) on Nov 21, 2008 at 15:12 UTC

    A test case calls for proof :)

    use strict; use warnings; use Text::CSV_XS; $/ = "\r"; print "Testing with version $Text::CSV_XS::VERSION\n"; my $csv = Text::CSV_XS->new ({ eol => $/ }); my $str = "a,b,c$/"; open my $fh, "<", \$str or die "ScalarIO: $!\n"; if (my $row = $csv->getline ($fh)) { print join "|", @$row, "\n"; } else { $csv->error_diag; }

    Generates:

    $ perl eoltest.pl Testing with version 0.58 a|b|c|

    Enjoy, Have FUN! H.Merijn