BioNrd has asked for the wisdom of the Perl Monks concerning the following question:
I would like to loop through a file that is setup like this.
And have it output based on the following bit of information: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
So the output I want is in the code above, I am just really struggling to get things to work as I would like.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
Any ideas are a big help.
Bio.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Loop, but print once.
by toolic (Bishop) on Mar 04, 2008 at 18:39 UTC | |
by Narveson (Chaplain) on Mar 04, 2008 at 20:00 UTC | |
by ikegami (Patriarch) on Mar 05, 2008 at 07:30 UTC | |
by Narveson (Chaplain) on Mar 07, 2008 at 06:24 UTC | |
by ikegami (Patriarch) on Mar 07, 2008 at 06:47 UTC | |
|
Re: Loop, but print once.
by jwkrahn (Abbot) on Mar 04, 2008 at 19:03 UTC | |
|
Re: Loop, but print once.
by Sinistral (Monsignor) on Mar 04, 2008 at 18:46 UTC |