Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
i just want to open 2 files and find difference between cond12 and cond22 and if the difference is greater than or equal to some number say 2 print the lines again in 2 different files.open FILE1,"1.txt" or die "can't open file 1"; open FILE2,"2.txt" or die "can't open file 2"; open(w1,">3.txt"); open(w2,">4.txt"); while (my $line1 = <FILE1>) { chomp $line1; my @cond1 = split("\t" , $line1); print "$cond1[2]\n"; while (my $line2 = <FILE2>) { chomp $line2; my @cond2 = split("\t" , $line2); print "$cond2[2]\n"; if(abs($cond1[2]-$cond2[2])>=2) { print w1 "$line1\n"; print w2 "$line2\n"; } } } close FILE1; close FILE2; close w1; close w2;
when i try this i am not able to get the output in proper way i mean my output should look like thisfile 1 (1.txt) aqw dfr 34 poilo ggg 98 file 2 (2.txt) qww asd 28 poilo ggg 97
it would not print the other lines since the difference is less than 23.txt aqw dfr 34 4.txt qww asd 28
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problem in looping
by kcott (Archbishop) on Aug 13, 2012 at 19:35 UTC | |
|
Re: problem in looping
by hbm (Hermit) on Aug 13, 2012 at 19:10 UTC | |
|
Re: problem in looping
by aitap (Curate) on Aug 13, 2012 at 23:35 UTC |