I want to compare 2 files and create third file with uncommon content.

e.g.

File 1
EC:1.1.1.42 isocitratedehydrogenase EC:1.1.1.44 6-phosphogluconatedehydrogenase EC:1.1.1.49 glucose-6-phosphate1-dehydrogenase
File 2
EC:1.1.1.42 isocitratedehydrogenase EC:1.1.1.44 6-phosphogluconatedehydrogenase EC:1.1.1.49 glucose-6-phosphate1-dehydrogenase EC:1.11.1.9 glutathioneperoxidase EC:2.5.1.16 spermidinesynthase EC:6.3.1.8 glutathionesynthase
Code that I have written
#!/usr/bin/perl $dir = "C:/Perl/bin/kegg"; open (FILE3,">>","$dir/keggdifference1.txt"); open (FILE4,">>","$dir/keggdifference2.txt"); open (FILE,"<","$dir/common.txt"); while (<FILE>) { chomp ($file=$_); @array =split (/\t/,"$file"); #print "$array[0]\n"; } open (FILE1,"<","$dir/bacillus1.txt"); while (<FILE1>) { chomp ($file1=$_); @array1 =split (/\t/,"$file1"); #print "$array1[3]\n"; } foreach ($array[0]) { foreach ($array1[3]) { if($array[0] eq $array1[3]) { print FILE3 "$array[0]\n"; } else { print FILE4 "$array[0]\n"; } } }
Code is not working.A new file is genertaed but consist of only last element of first file.Plz help me in this regard.

In reply to comparing 2 files and creating third file with uncommon content by rashichauhan

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.