mecrazycoder has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, Greetings to all.Right now i am writing a script to populate various tables using CSV files. Since tables are not having same number of columns, my script as to be change on regular basis according to the tables.Is there any general way to insert values into columns of different tables with varying in number of columns.So that by giving CSV files and table name alone, script should be able to insert values into given table. Thanks in advance

Replies are listed 'Best First'.
Re: Insert using CSV
by Corion (Patriarch) on Nov 03, 2009 at 10:24 UTC

    Yes. See DBI for writing, and Text::CSV for reading. I'm not sure where your problem is, so I can't be more specific.

      Thank you. Since the script that i am developing ahould be able to populate any tables using CSV files. Since tables will not have same column name and number of columns, how i achieve the script to support different tables.

        I don't know. Somehow you will need to correlate the column names in the tables with the columns of the CSV file. Maybe the Syntax of the SQL Insert Statement can help you, assuming that the columns in the CSV file are in the same sequence as the column declarations in your database?

        You will have to show a bit more code so we can see where your actual problem is. This site is not a script writing service where people write complete Perl scripts for you. We expect you to put some effort into researching the subject matter and presenting a first approach.