I think I see some problems. In

while (<FILE2>) { push @col, $_ =~ m/^(\S+)/ unless ...; }

you probably want to say my @col, otherwise @col keeps accumulating stuff from the previous pass through the first while loop.

Likewise, in

while(<COL>) { $_ =~ s/^(\S)/$1 $col[$i++]/; print OUT2 $_; }

you probably want to say my $i++

so $i starts at 0 again, instead of being left with whats in it from the while (<COUNT>) loop.

And again, in

while (<COUNT>){ ($i, $j) = ...

it would be good if you used

my ($i, $j)

You also create and destroy the TRUE_OUTPUTS file each time through the loop. But from what you've shown, it never changes. So it would be better to put this at the top:

open (FILE, "test.pat") or die "Can't open test.pat: $!"; open (OUT, ">TRUE_OUTPUTS") or die "Can't open TRUE_OUTPUTS: $!"; while (<FILE>) { if ($_ =~ m/^\s{4,}(\d)\s+$/) {print OUT "$1\n"} } close (FILE); close (OUT);

Note that I used a constant "test.pat" since you said that doesn't change. I also added die and tidied up the regex by using {4,} to match 4 or more.

Also, you forgot the die in

open (COUNT, "<COMPARE") or "Can't open COMPARE: $!";

And now, just to be nitpicky, $output seems like a bad variable name. I think $input_file or just $input would be better.

Hope this helps.

TheEnigma


In reply to Re^5: while loop returns same values by TheEnigma
in thread while loop returns same values by Anonymous Monk

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.