in reply to Need help with double quotes and CSV file processing

use Text::CSV;

Here is a tutorial to get you started.

From Text::CSV:

quote_space

By default, a space in a field would trigger quotation. As no rule exists this to be forced in CSV, nor any for the opposite, the default is true for safety. You can exclude the space from this trigger by setting this option to 0.

Removing all commas inside a field is a matter of:

s/,//g; ## OR ## # tr/,/ /;

             When in doubt, mumble; when in trouble, delegate; when in charge, ponder. -- James H. Boren

Replies are listed 'Best First'.
Re^2: Need help with double quotes and CSV file processing
by Tux (Canon) on Nov 04, 2013 at 20:43 UTC

    I just looked at that "tutorial", and have to conclude that to be be one of the worst tutorials I have ever seen. THE reason to use a CSV parsing module like Text::CSV_XS or Text::CSV is because, like in the case of the OP, the format is not straightforward: fields may contain " or , or even newlines. Both mentioned modules deal with that transparently.

    My advice: DO NOT READ that tutorial. Just read the manual for either module and follow the SYNOPSIS and examples:

    my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 }); open my $fh, "<", "file.csv" or die "file.csv: $!"; while (my $row = $csv->getline ($fh)) { # do something with @$row } close $fh or die "file.csv: $!";

    update 2013-11-25: That tutorial has been completely rewritten to reflect the current state of affairs, and is now well worth looking at.


    Enjoy, Have FUN! H.Merijn