Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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 ( #1208161=note: print w/replies, xml ) Need Help??


in reply to Re^2: 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

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} ]);.

  • Comment on Re^3: Modifying an existing Perl script to ask for input and output filenames and also remove double quotes for outfile file
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1208161]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2020-10-01 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (15 votes). Check out past polls.

    Notices?