in reply to Re: Modifying an existing Perl script to ask for input and output filenames and also remove double quotes for outfile file
in thread Modifying an existing Perl script to ask for input and output filenames and also remove double quotes for outfile file

Removing the use of Text::CSV is a major backward step! Consider what happens if a family of products have titles of the form:

Nugget Type Acme Widget, blue

Your code will now generate a badly formed csv file because the comma in the product title is seen as a field separator. With Text::CSV generating the output at least the file is generated correctly and the comma containing title is correctly quoted.

Premature optimization is the root of all job security
  • Comment on Re^2: Modifying an existing Perl script to ask for input and output filenames and also remove double quotes for outfile file
  • Download Code

Replies are listed 'Best First'.
Re^3: Modifying an existing Perl script to ask for input and output filenames and also remove double quotes for outfile file
by Cristoforo (Curate) on Jan 31, 2018 at 01:08 UTC
    I agree much with you Grandfather, however he stated in his post-
    When I run the script on my input.csv file the output.csv file which is created by the script has double quotes in two of the data columns, i.e. the Timestamp field "2018-01-23 00:00" and the ProdDescription field "Acme Widget Large 20 inch" These double quotes need to be removed to comply with the required data format of the final csv file.
    So I don't know if he sends the result somewhere, they will be able to parse a proper CSV file.

    Needed additions/changes to the script to make it proper would be:

    Add use Text::CSV; in the header with the other use statements.

    Create a new csv object, my $csv = Text::CSV_XS->new({binary => 1, eol => $/}); before the while loop.

    Instead of the print statement, use $csv->print($out, [ @tmp{@cols} ]);.