in reply to Re^2: Creating .csv file with comma
in thread Creating .csv file with comma

I needed to fix the code to make it work and show the issue with double quotes twice.
#!/usr/bin/perl use strict; use warnings; use Text::CSV; my $number = "100"; my @data = (); push @data, [ '1234565', "Prototype", '"Number in address is '.$number.'. Please, Please check + your records."', ]; my $data = \@data; my $csv = Text::CSV->new ( { binary => 1, eol => "\n", quote_char => +'', } ) or die "Cannot use CSV: ".Text::CSV->error_diag (); open my $fh, ">", "myfile.csv" or die "Unable to create file: $!"; $csv->print($fh, $_) for @{ $data }; close $fh;

Sorry for that! Thanks!

Replies are listed 'Best First'.
Re^4: Creating .csv file with comma
by haukex (Archbishop) on Apr 24, 2020 at 17:29 UTC

    As I showed, remove the quote_char => '' option and remove the double quotes from inside the string '"Number in address is '.$number.'. Please, Please check your records."'.

      This line fixed my issue with the code:

      my $csv = Text::CSV->new ( { binary => 1, auto_diag=>2, escape_char => + "\\", eol => "\n", quote_char => '', } )


      Thanks for all the help!!
Re^4: Creating .csv file with comma
by soonix (Chancellor) on Apr 24, 2020 at 15:40 UTC
    So why do you put "1234565" and 'Prototype' in one pair of quotes each, and the third element in two pairs of quotes?

    You don't need an extra pair of quotes for the comma, that is Text::CSV's Task