Hi Monks,

I have written the following script to read the second column of many tab delimited files (~200) and merge them side by side in an output file. The input files have three columns, tab delimited separated and 6.9 million lines each. It will take forever, if I want to read and write 6.9 million lines. Do you have any other better solution to do it quicker and more efficient.

#!/usr/bin/perl -w my(@handles); unlink"Results.txt"; #would loop if already present for(<*.TI>){ open($handles[@handles],$_); } open(OUTFILE,">Results.txt"); my$atleastone=1; while($atleastone){ $atleastone=0; for my$op(@handles){ if($_=readline($op)){ my@col=split; $col[1]+=0; #otherwise you print nothing but a \t if column 2 i +s undef print OUTFILE"$col[1]\t"; $atleastone=1; }else{ print OUTFILE"0\t"; } } print OUTFILE"\n"; } undef@handles; #closes all files close(OUTFILE);

In reply to Merging Many Files Side by Side by sesemin

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.