Hi all, let's say if
text1: apple orange text2: apple apple
I try to delete the keys which are common in both text (only match once) and print out the mismatch. Apple of line 1 from text 1 and apple of line 1 from text 2 match, therefore deleted. But somehow apples of both lines in text 2 were deleted. Is there any better ways to delete just once for each existed data? After all of your generous help and tips,here is the code I have written. Cheers.
use strict; use warnings; open (FILE, "a") or die "Unable to open ref file.\n"; chomp (my @data1 =<FILE>) ; close(FILE); open (FILE, "b") or die "Unable to open new file.\n"; chomp (my @data2 =<FILE> ); close(FILE); my $size = @data1 < @data2 ? @data1 : @data2; my $result= @data1 < @data2 ? "File 1 has missing data" : "File 2 has +missing data"; my $ori = @data1 == @data2 ? 1:0; my $i; for( $i = 0; $i < $size; $i++){ if ($data1[$i] ne $data2[$i]){ printf "%s is mismatch with %s\n",$data1[$i],$data2[$i]; } else { printf "%s is match with %s \n",$data1[$i],$data2[$i]; } } print "$result\n" if (!$ori);
Output:
apple is match with apple File 2 has missing data
Another method I have tried by comparing the arrays one by one. But there is a tricky part. What if Text 1 has one line while Text 2 has two lines?

In reply to Perl delete function by annel

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.