Hello all. I'm just getting started with Perl and I'm currently working on a script to convert fixed-width text records in a flat-file database to delimited-field records. The script works fine with one exception: it's really slow. I'm dealing with a large amount of data (usually millions of records) and the script takes a really long time. I'm just not sure I'm handling this problem in the most efficient manner. In the script, I'm converting each fixed-width record (a single line in a text file) into individual fields separated by some delimiter (a comma, for instance). Once I do this, I write the delimited record and a line ending (\n) out to an output file (using a print statement).

My question is: Is there a more efficient way to do this? On a test conversion, a file containing 554,152 records took over 16 minutes to complete. I just want to make sure I'm doing this as efficiently as possible and not dragging the process out unnecessarily.

Any assistance would be greatly appreciated.

Thanks in advance,

Larry Polk
larry@larrypolk.com


In reply to What's the most efficient way to write out many lines of data? by Anonymous Monk

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.