in reply to Vertical split (ala cut -d:) of a file

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.