in reply to Optimizing slow restructuring of delimited files
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@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;
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"; }
|
---|