in reply to Re^2: Escape Double Quotes
in thread Escape Double Quotes

Read the docs on that option: It keeps the metadata separately from the data, so to find out if a field was quoted, you need to look at the is_quoted method. Even though it's not a perfect solution, you could just tack the quotes back onto the field if is_quoted is true. (Perhaps another monk more versed in Text::CSV has a better solution.)

Replies are listed 'Best First'.
Re^4: Escape Double Quotes
by Tux (Canon) on Aug 07, 2014 at 15:59 UTC

    You are completely right, and there is no easier way to do it

    use Text::CSV_XS; my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1, keep_meta_info => 1, }); my $file = $ARGV[0] or die "Need to get CSV file on the command line\n +"; my $sum = 0; open my $data, "<", $file or die "Could not open '$file' $!\n"; while (my $row = $csv->getline ($data)) { foreach my $idx (0 .. $#row) { $csv->is_quoted ($idx) or next; $row->[$idx] =~ s/(.*)/"$1"/; # TIMTOWTDI } # @$row is now quoted as you want } close $data;

    Enjoy, Have FUN! H.Merijn