I have 2 files and i want to diff the two files such that i have 3 files at the end of the diff
1. UniqueDataInFile1

2. UniqueDataInFile2

3. CommonData
This is the code that i have come up with so far...it is not right and i am not clear on how i can iterate till eof of first file and look for the item in file1 in file2. Will appreciate any pointers, help here and no i am not trying to get someone to do my homework. TIA

my $infile1="infile1.txt"; my $infile2="infile2.txt"; open INFILE1, '<', $infile1 or die "could not open '$infile1' $!"; open INFILE2, '<', $infile2 or die "could not open '$infile2' $!"; open (FileA, ">DataFromFile1.txt") || die "Unable to open TextInFile1O +nly.txt for writing \n"; #open (FileB, ">DataFromFile2.txt") || die "Unable to open TextInFile1 +Only.txt for writing \n"; open (FileC, ">CommonDataFromTwoFiles.txt") || die "Unable to open Tex +tInFile2Only.txt for writing \n"; my @dataInFile1=<INFILE1>; my $val; my @ArrayA; my $last_element; while(my $line=<INFILE2>) { if ($line=~ m/$dataInFile1[0]/i) { print FileC $dataInFile1[0]; push @dataInFile1, shift @dataInFile1; } }

infile1
--------

yahoo

google

msn,/br.
abc

infile2
--------

yahoo

google

safeway

walmart

kmart

output1
--------

msn

abc

output2
--------

safeway

walmart

kmart

output3
--------
yahoo
google


In reply to Diff 2 files and print output to file 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.