I am calling a webservice that’s returning a comma separated dataset with varying columns and multiple text-qualified rows (the first row denotes the column names) . I need to insert each row into a database while concatenating the rows that are varied.
The data is returned like so
"Email Address","First Name","Last Name", "State","Training","Suppression","Events","MEMBER_RATING","OPTIN_TIME","CLEAN_CAMPAIGN_ID"
"scott@example.com","Scott","Staph","NY","Campaigns and activism","Social Media","Fundraiser",1,"2012-03-08 17:17:42","Training"
There can be up to 60 columns between State and Member_Rating, and the data in those fields are to get concatenated and inserted into one database column. The first four fields and the last three fields in the list will always be the same. I’m unsure the best way to tackle this.
I am not sure if this solution fits your needs. I hope so. It’s a
perlscript that joins with-surrounded with spaces all fields but first four and last three. It uses a non standard module,Text::CSV_XSthat must be installed usingCPANor similar tool.Content of
infile:Content of
script.pl:Run it like:
With following output: