|Welcome to the Monastery|
DBD::CSV - How to insert a new column with column header in an existing CSV fileby slayedbylucifer (Scribe)
|on Jul 19, 2012 at 11:59 UTC||Need Help??|
slayedbylucifer has asked for the
wisdom of the Perl Monks concerning the following question:
Hi, I want to insert a new column along with the column header in an existing csv.
e.g. I have below csv:
I am using DBD::CSV in my script to generate above mentioned file
Now, I want to add a 3rd column in above file to make it look like below:
I tried doing below with the DBD::CSV but it did not work:
but I get below error:
So I am thinking that DBD::CSV needs column name present already. So, I added the column name manually to the original csv file and ran above code and still it failed with same error.
Could you guide on how to get a column inserted in csv along with the column name. Also, just so you know, the values in this 3rd column will depend on some comparison of the respective values in column 1 and column 2 of the row. I'm hoping DBD::CSV should be able to do that because AFAIK Text::CSV does not have a mechanism to deal with column names.