Hello Monks,
I have written a simple script to read a tab-delimited file and write out a few selected columns to another tab-delimited file. Although my script is working OK, it seems to take more time than it should. It took 44 seconds to do its thing on a 4.22 MB file (2796 lines). Any insight would be greatly appreciated.
Here's the code:
while(<INFILE>)
{
# get the current line and split into it's columns
@Line = split /\s+/, $_;
#print the selected columns to the output
print OUTFILE join("\t",@Line[@ColumnNumbers]),"\n";
}
The @ColumnNumbers array has been defined previously, and would look something like: (1,10,32,69,200,291)
UPDATE:
The problem turned out not to be related to the code above. Thanks for the input though. Turns out I was running another algorithm every time through the loop that I thought I was only running the first time.
Retitled by davido from 'Why is this so slow?'.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.