in reply to Perl: How to print unmatched data after comparison of two files?
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, |
|
|---|