You didn't give much to go on but my first hypothesis would be disk I/O. If the file size is small, you could try assigning the entire file to an array and parsing that. Something like
@filetoread = <INFILE>; # read in file all at once
my $linestooutput = ''; # place to save output until the en
+d
foreach (@filetoread){
@Line = split /\s+/; #split defaults to $_
$linestooutput .= join("\t",@Line[@ColumnNumbers])."\n";
}
print OUTFILE $linestooutput; # write output
# or even shorter
@filetoread = <INFILE>;
$linestooutput .= join("\t",(split /\s+/)[@ColumnNumbers])."\n" foreac
+h (@filetoread);
print OUTFILE $linestooutput;
I'm not sure about the speed impact of interpolated splices? I don't imagine that is the issue but you could try something like this
while(<INFILE>)
{
# get the current line and split into it's columns
@Line = split /\s+/, $_;
#print the selected columns to the output
my $outline .= @Line[$col]."\t" foreach my $col (@ColumnNumbers);
print OUTFILE $outline,"\n";
}
PJ
use strict; use warnings; use diagnostics;
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.