makamaka / Text-CSV

comma-separated values manipulator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Text::CSV_PP can't say a field when it contains new line.

aero opened this issue · comments

commented

Hi,

Text::CSV_PP can't say a field when it contains new line.

t.csv

no,name,data
1,tom,"PING
FAIL"
2,john,"PING\nFAIL"
$ perl -MText::CSV=csv -e '$c=Text::CSV->new; foreach (@{csv({ in=>"t.csv", headers => "auto" })  }) { $_->{data} =~ /PING/ && $c->say(STDOUT,[@$_{qw/name data/}]) }'
tom,"PING
FAIL"
john,PING\nFAIL

Text::CSV(aka. Text::CSV_XS) works as expected.



$ perl -MText::CSV_PP=csv -e '$c=Text::CSV_PP->new; foreach (@{csv({ in=>"t.csv", headers => "auto" })  }) { $_->{data} =~ /PING/ && $c->say(STDOUT,[@$_{qw/name data/}]) }'
john,PING\nFAIL

where's tom row??


$ perl -MText::CSV_PP=csv -e '$c=Text::CSV_PP->new; foreach (@{csv({ in=>"t.csv", headers => "auto" })  }) { $_->{data} =~ /PING/ && $c->say(STDOUT,[@$_{qw/name/}]) }'
tom
john

works as expected. 
It seems that Text::CSV_PP can't say(print) a field when it contains new line properly.
but no problem with Text::CSV_XS.

Edited:
Text::CSV_PP also works well with binary mode.
https://metacpan.org/pod/Text::CSV#Embedded-newlines

$ perl -MText::CSV=csv -e '$c=Text::CSV->new; $c->binary(1); foreach (@{csv({ in=>"test.csv", headers => "auto" })  }) { $_->{data} =~ /PING/ && $c->say(STDOUT,[@$_{qw/name data/}]) }'
tom,"PING
FAIL"
john,PING\nFAIL

Why Text::CSV_XS and Text::CSV_PP are different ?