You're reading the file twice in your loop, first in the condition then again before the end of the loop, is this intentional? Also a few other suggestions - your match regex ^R.* can drop the .* as it achieves nothing because it says match 'R' at the beginning of the string, optionally followed by 0 or more of anything, in fact it would be better suited with a simple index. You could also drop the indexing using $i and replace it with the push function e.g
while ( $line = <TR_INFILE> ) { if ( index( $line, 'R' ) == 0 ) { ## removed /g as it's unnecessary $line =~ s/^Results://; print OUTFILE3 "$line"; ## the ' ' is special, see. perldoc -f split my @chunks = split ' ', $line; push @trstart, shift @chunks; push @trend, shift @chunks; push @period, shift @chunks; push @copy, shift @chunks; push @consize, shift @chunks; push @matches, shift @chunks; push @indels, shift @chunks; push @score, shift @chunks; push @numa, shift @chunks; push @numc, shift @chunks; push @numg, shift @chunks; push @numt, shift @chunks; push @entropy, shift @chunks; $TRID++; } elsif ( index($line, 'S') == 0 ) { $line =~ s/^Sequence:\s*//; push @TR_Accession, $line; $SEQID++; } }
Some of that code massaging is style but it will also be much faster than your current code as most of the fiddly stuff is now done by perl and it also saves a lot of hard-coding. See. push, index, shift for more info on the functions used above.
HTH

_________
broquaint


In reply to Re: RegEx misbehaving? by broquaint
in thread RegEx misbehaving? by pdotcdot

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.