Monks,

I would like to loop through a file that is setup like this.

1\t300\t1_a\t30\t1_b\t20 1\t300\t2_a\t22\t2_b\t12 1\t320\t1_a\t10\t1_b\t30 1\t320\t2_a\t32\t2_b\t22 2\t312\t1_a\t30\t1_b\t20 2\t312\t2_a\t22\t2_b\t12 2\t310\t1_a\t31\t1_b\t20 2\t310\t2_a\t21\t2_b\t12
And have it output based on the following bit of information:
while (<FILE>) { #containing the above information chomp; my @temp_array = split(/\t/,$_); for (1 .. 2) { #arbitary number based on outside factor my $pop_tracker = $_; if ($temp_array[0] == $pop_tracker) { print $temp_array[0]; #I want this to only print once. #more print statements here to reflect the below output. } } # I want: 1 - 300 1_a 30 1_b 20 2_a 22 2_b 12 320 1_a 10 1_b 30 2_a 32 2_b 22 # 2 - you get the idea... #Not: 1 - 300 1_a 30 1_b 20 1 - 300 2_a 22 2_b 12 1 - you get the idea... 1 - some info 2 - some info 2 - some info 2 - some info 2 - some info
So the output I want is in the code above, I am just really struggling to get things to work as I would like.

Any ideas are a big help.

Bio.

---- Even a blind squirrel finds a nut sometimes.

In reply to Loop, but print once. by BioNrd

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.