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

Hi experts, I need a perl script for this question:- Question :- I would like to upload a comma separated file(say xl sheet file) to the server and insert the file values into the database. How can i do that? file contains two columns (field1 for Number and field2 for Name). Thanks

Replies are listed 'Best First'.
Re: xl file to database
by hardburn (Abbot) on Jun 12, 2003 at 17:49 UTC

    A few modules that might be helpful:

    The documentation for those should be enough to get you started.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated

Re: xl file to database
by daeve (Deacon) on Jun 12, 2003 at 23:56 UTC
    There are some Tutorials here at The Monastery on perl in general as well as some dealing with just databases that might help. There is also Super Search for the numerous nodes on databases and perl.

    HTH
    Daeve

Re: xl file to database
by Zero_Flop (Pilgrim) on Jun 13, 2003 at 05:30 UTC
    A quick search on google for "excel2mysql.pl" will get you what you want. If you do not want to go with mysql, then you will have to do a little perl brain power to convert it for your db
Re: xl file to database
by Itatsumaki (Friar) on Jun 12, 2003 at 18:02 UTC

    Further, Perl's database interface, DBI, isn't always (usually?) the best way to load large quantities of data into a DB. Most databases have their own bulk-loaders that are often much faster. For instance, MS-Access has an import function while Oracle has SQL/Loader.

    -Tats

    Update: /me shame-facedly changes PERL to Perl. Thanks anony-brother!

      Perl, not PERL!
      Postgres has this too. There is a COPY command that you can find out more about through psql:
      db=> \h COPY Command: COPY Description: copy data between files and tables Syntax: COPY table [ ( column [, ...] ) ] FROM { 'filename' | stdin } [ [ WITH ] [ BINARY ] [ OIDS ] [ DELIMITER [ AS ] 'delimiter' ] [ NULL [ AS ] 'null string' ] ]
      You can also copy a table to a file. This may not be available through DBI but you can always create the file and then system "psql < file_to_copy_in";.

      --tidiness is the memory loss of environmental mnemonics