Hello WWq, and welcome to the Monastery!

To expand on the reply from Loops:

There are a number of problems with the code as posted. First, it is incomplete: FILE1, FILE2, NL, and especially $line3 are used without being declared or initialised. Do you use strict and use warnings at the top of your code?

Second, the array @arr3 is cleared (by being reset to @emptyarr) each time the condition evaluates to true within the first foreach loop. So, after leaving that loop, @arr3 can never contain more than one element. That is, the second foreach loop can have at most one iteration.

Now to two matters of style: (1) Variables should be declared as close as possible to the point of first use. In particular, your loop variables can safely be declared like this:

foreach my $line (@arr2) {

(2) Code should be indented to make it easy to see where each structure begins and ends. For example:

foreach my $line2 (@arr3) { foreach my $line1 (@arr1) { if ($line1 =~ m/(.*)\s+(.*)\s+(.*)\s+(.*)\s+(.*)\s+(.*)\s+(.*) +\s+(.*)/) { my $cname1 = "$2"; if ($cname1 ne $line3) { print "$cname1\n"; } } } }

It would also help the monks if you placed your data (the contents of files 1 and 2) within <code> tags, as you’ve done with the code.

To answer your problem, we will need to know what $line3 is supposed to contain.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Perl: How to print unmatched data after comparison of two files? by Athanasius
in thread Perl: How to print unmatched data after comparison of two files? by WWq

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.