If you have shell access to the database server, your best bet is to write a really simple perl script that just converts the original text file into another plain-text format that can be loaded directly into the table via the database server's native "import" or "load" tool.

If your text file is just a few (hundred) records, you might not notice the speed difference, but if it runs into the many thousands of records, the 10-to-1 or worse wall clock ratio (DBI inserts vs. bulk insert using the right tool) will be significant. This is equally true for mysql, oracle, postgres, etc.

Regardless of the number of records involved, you'll spend a lot less time programming, and it will be a lot easier to get right.

(If you don't have shell access, but are using mysql, it is still likely to be easier/better to upload a properly formatted version of the text file and use "LOAD DATA INFILE ...", rather than a do bunch of DBI inserts.)


In reply to Re: Run one perl script from another? by graff
in thread Run one perl script from another? by punch_card_don

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.