in reply to Re: Looking for elegant solution to dbi coding problem
in thread Looking for elegant solution to dbi coding problem

Aside: is there a way for me to reply to my own thread, or do I have to 'reply' to a specific response?

Thanks for the ideas everyone... I'm still getting the hang of perl, but I always learn a tremendous amount when I spend time on these forums. Comments on the first three replies:

1 That regexp took me a while to understand, as I wasn't familiar with "?:", but I finally managed to grok it :)

2 Cool, I didn't realize that I could use a negative limit in the split function to address this problem.

3 I see your point... it would be far more economical to go that route (in combination with the modification to split proposed in number 2)

Thanks again!

Retitled by holli from 'Followup'.

  • Comment on Re: Looking for elegant solution to dbi coding problem

Replies are listed 'Best First'.
Re: Re: Looking for elegant solution to dbi coding problem
by graff (Chancellor) on Jul 16, 2005 at 05:40 UTC
    If you're starting from a tab-delimited data file (and if there is a lot of data to be inserted), it's likely to be even more economical to use mysqlimport (command line interface to mysql's LOAD DATA statement). Or -- I haven't tried this yet -- maybe you can use LOAD DATA via DBI.pm? The point being that loading the data in bulk with tools built for this purpose will be incredibly faster than one-row-at-a-time inserts with DBI.
      I first explored the idea of directly importing the data with the mysql INFILE command, but I was getting a large number of errors during the import (and MySQL is less than helpful when it comes to elucidating these errors). So, I elected to write a script that would assure that the data were properly formatted prior to insertion. However, I will explore the LOAD DATA function... I was not aware of it prior to your mention.

      Thanks!
        I elected to write a script that would assure that the data were properly formatted prior to insertion.

        Well then, why not write a script that doesn't use DBI at all, but simply reads the original tab-delimited text file and writes a "fixed" version of it that mysql's import tool will accept? It should end up being the same amount of programming work or less, compared to doing the job with DBI -- you still have to understand what the problems are with the original data, and how to fix them (unless you end up taking short cuts in the DBI approach, either intentionally or accidentally, that result in the "large number of errors" being ignored rather than fixed, but you probably don't want that sort of short cut). And of course the script without DBI and inserts will run a lot faster than the DBI approach.

        I think your reference to INFILE and my reference to LOAD DATA are actually referring to the same process. I know that when you run mysql directly, you can issue a LOAD DATA command as an sql statement, but I don't know for sure if this can be used via DBI -- it's worth a try.

Re: Re: Looking for elegant solution to dbi coding problem
by planetscape (Chancellor) on Jul 16, 2005 at 16:05 UTC

    You can reply to your own post the same basic way you reply to any other. Scroll down to just below your post, and look for the line beginning "comment on {post title}". (Or: click here)

    For the convenience of people reading Newest Nodes or stumbling upon your post from other areas of the site, do please try to preserve information in the title of your reply so that some context is immediately apparent (see my title, above). Thanks!

    planetscape