qhayaal,

It doesn't really matter what happens under the covers, the computer simply must go through the file line by line to find two things: the text you're cutting on (":"), and the newline to signify the next line starting. Whether you do this via while(<$fh>) { my ($field) = split /:/; do_stuff_with($field); }, or you do it via Text::xSV, or you do it via my @fields = `cut -d: -f1 $file` or even my @fields = `awk -F: '{print \$1}' $file`, the computer will go through each file, line by line, inspecting characters. (Note that with the split example, we want to give it an array context - split is really special in that it can "see" how many fields are wanted, and will only split into one more field than that - so it will only look for one ":" in the string, already being as efficient as split can be.)

If you really think you need the speed, first try it with one of the above (I would recommend one of the first two). If it really is too slow (I doubt it will be), there are some optimisations you can make:

Now, having said all that, I want to re-iterate: TEST OUT THE SPLIT (or Text::xSV) FIRST. It's probably more than fast enough, with the least amount of effort. Most of the rest of the above suggestions will only shave a fraction of a percent from the time, if they shave anything, with huge amounts of programmer time dedicated to it, also meaning large chances of bugs to find and eradicate.


In reply to Re: Vertical split (ala cut -d:) of a file by Tanktalus
in thread Vertical split (ala cut -d:) of a file by qhayaal

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.