Hi! I am trying to compare columns in all possible combination, I have two files one with all possible combination and other with data

file2

1 2 3 4 1 2 3 5 1 2 4 5 1 3 4 5 2 3 4 5

file1

A B C D E 0 0 0 + 0 + 0 + + + 0 + + + + 0 0 + + 0 + + + + + 0 + + + + + 0 + + 0

so far I have tried this, but it seems only first line of file2 is getting parsed to while loop

open (BC,"file2.txt")||die("cannot open"); open (AB,"file1.txt")||die("cannot open"); @file=<BC>; chomp(@file); foreach $fl(@file) { if($fl=~/(.*?)\s+(.*?)\s+(.*?)\s+(.*)/) { $w=$1-1; $x=$2-1; $y=$3-1; $z=$4-1; } while(<AB>) { @data=split("\t",$_); chomp(@data); push(@col1,$data[$w]); push(@col2,$data[$x]); push(@col3,$data[$y]); push(@col4,$data[$z]); } } for($i=1;$i<@col1;$i++) { if(($col1[$i] eq '+') && ($col2[$i] eq '+') && ($col3[$i] eq +'+')) { $j++; } if(($col1[$i] eq '+') && ($col2[$i] eq '+') && ($col4[$i] e +q '+')) { $k++; } if(($col3[$i] eq '+') && ($col2[$i] eq '+') && ($col4[$i] eq ' ++')) { $l++; } if(($col3[$i] eq '+') && ($col2[$i] eq '+') && ($col4[$i] eq + '+')&&($col1[$i] eq '+') ) { $m++; } print $col1[0],"\t",$col2[0],"\t",$col3[0],"\t\t",$j,"\n"; print $col1[0],"\t",$col2[0],"\t",$col4[0],"\t\t",$k,"\n"; print $col4[0],"\t",$col2[0],"\t",$col3[0],"\t\t",$l,"\n"; print $col1[0],"\t",$col2[0],"\t",$col3[0],"\t",$col4[0],"\t",$m," +\n"; }

desired output

A B C 1 A B D 1 D B C 3 A B C D 1 A B C 1 A B E 1 E B C 3 A B C E 1 A B D 1 A B E 1 E B D 3 A B D E 1 A C D 3 A C E 2 E C D 4 A C D E 2 B C D 3 B C E 3 E C D 4 B C D E 3
thank you

In reply to compare columns in all possible combination 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.