in reply to Text::CSV and escaped quotes

Check the escape_char setting.

Adding this line after the loop shows " is the escape_char.

say $csv->escape_char;

Getting it to import also needs a few other settings, so perhaps the auto_diag process needs work, or this is just difficult data to auto diagnose.

I also re-arranged the code to work on my machine and added a use 5.010;.

use strict; use warnings; use 5.010; use Text::CSV qw(csv); my $csv = Text::CSV->new ({ binary => 1, auto_diag => 1, escape_char => '\\', quote_char => "'", allow_whitespace => 1 }); my $o = \*STDOUT; # Read/parse CSV while (my $row = $csv->getline (\*DATA)) { my @selected = ( splice(@{$row}, 0, 2), splice(@{$row}, -6, 2) ); $csv->say($o, \@selected); } say $csv->escape_char; exit(0); __DATA__ 8, 9, NULL, 'Filler', '555-999', '77:88', 0, 0, 0, 0 8, 9, NULL, 'Filler', '555-999', '77:88', 'A \' B , C', 0, 0, 0 8, 9, NULL, 'Filler', '555-999', '77:88', 0, 0, 0, 0

Replies are listed 'Best First'.
Re^2: Text::CSV and escaped quotes
by mldvx4 (Friar) on Sep 29, 2023 at 00:20 UTC
      The one I keep running into is where they don't bother escaping anything, and just hope the quotes work out.

      There's a setting for that too!

A reply falls below the community's threshold of quality. You may see it by logging in.