345qwerty has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I have such problem: I want to print all lines with new added column: IN or OUT, the script runs, but I can't understand, why there is only first line printed...do you have any suggestions?
This is my script:
use strict; use warnings; open(FILE, "Q.txt"); my $file = <FILE>; my @column; while (<FILE>) { @column=($file); chomp @column; my $number=0; while($number <= $#column) { #go through the array from 0 to th +e last element my $j; my $count=0; foreach ($j=$number; $j < $#column; $j++) { #select the numbers + from the beginning of the line my $d=($column[$j]=~/(\d+)/)[0] - ($column[$j+1]=~/(\d+)/)[0]; #d +ifference last if abs($d)!= 1; #if differ more than 1 - lea +ve. $count+=$d; #accumulate the difference. } if(abs($count)>=8) { $column[$_].= " t\IN " for $number..$j; $number=$j+1; } if(abs($count)<8){ $column[$number].= " \tOUT" ; $number++; } } } print for @column; exit;
And here is my INPUT FILE:
5 Q CAA 16 Q CAG 21 Q CAA 74 Q CAA 80 Q CAG 82 Q CAG 84 Q CAG 85 Q CAG 89 Q CAG 90 Q CAG 91 Q CAG 92 Q CAG 93 Q CAA 94 Q CAG 95 Q CAG 96 Q CAG 98 Q CAG 99 Q CAG 100 Q CAG 101 Q CAG 102 Q CAG 106 Q CAG 107 Q CAG
Here is my OUTPUT FILE, but here is just the 1st line...:
5 Q CAA OUT
Thank you!
2017-08-12 Athanasius added code tags around data
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How can I print all lines?
by hippo (Bishop) on Aug 09, 2017 at 09:27 UTC | |
by 345qwerty (Novice) on Aug 09, 2017 at 09:33 UTC | |
by hippo (Bishop) on Aug 09, 2017 at 09:41 UTC | |
by 345qwerty (Novice) on Aug 10, 2017 at 11:52 UTC | |
by SuicideJunkie (Vicar) on Aug 10, 2017 at 15:00 UTC | |
Re: How can I print all lines?
by marto (Cardinal) on Aug 09, 2017 at 09:53 UTC | |
Create separated column for my file
by 345qwerty (Novice) on Aug 10, 2017 at 10:47 UTC | |
by thanos1983 (Parson) on Aug 10, 2017 at 11:04 UTC | |
| |
by kcott (Archbishop) on Aug 11, 2017 at 06:53 UTC |
Back to
Seekers of Perl Wisdom