0

I had moved from Text::CSV to the XS version because of a problem of newline inside data Text::CSV parsing when data contains newline

Text::CSV_XS removes all the escape chars in the data ( I am using linux with perl 5.8.8 ) This is the sample code (below)

I expect that the attribute on the 3 row should be \N after escaping 1 \ but Text::CSV_XS removes both the \

use strict;
use warnings;
use Text::CSV_XS;

my $csv = Text::CSV_XS->new({
    binary => 1,
    eol => "\n",
    quote_char => '"',
    escape_char => '\\',
    auto_diag => 2,
    allow_loose_escapes => 1,
}) or die "Can't create CSV parser";

while( my $row = $csv->getline(\*DATA) ) {
    print join(" ",@{$row})."\n";
}

__DATA__
ata,atb,atc
1a,"1b                                                                                                                                         
1b-continued",1c
\\N,2b,2c

This is the output

ata atb atc
1a 1b
1b-continued 1c
N 2b 2c
Community
  • 1
  • 1
Ram
  • 1,155
  • 13
  • 34
  • It only removes the backslashes if you set `escape_char => '\\'`. I am wondering if you have not misunderstood what that option does. – TLP Sep 02 '13 at 12:55

1 Answers1

1

Use allow_unquoted_escape => 1 (available since version 0.95).

ikegami
  • 367,544
  • 15
  • 269
  • 518
  • I think this parameter is not implemented in the XS module I get this error ` ` # CSV_XS ERROR: 1000 - INI - Unknown attribute 'allow_unquoted_escape' @ pos 0 Can't create CSV parser at parse1 line 6. – Ram Sep 03 '13 at 05:33
  • You must have an older version – ikegami Sep 03 '13 at 11:11