On Jan 29, [EMAIL PROTECTED] said:
>1- report any objects in File A that are not in File B
>2- report any objects that are in File B but not in File A
This sounds like the job for two hashes. It also happens to be in the FAQ
under the heading "How do I compute the difference of two arrays? How do
I compute the intersection of two arrays?" and is accessible via the
command:
perldoc -q 'difference'
But here's some applicable code for you.
my (%seen, @a, @b);
open FIRST, "< file_a" or die "can't read file_a: $!";
open SECOND, "< file_b" or die "can't read file_b: $!";
while (<FIRST>) {
chomp;
$seen{$_} = 1;
}
while (<SECOND>) {
chomp;
# it's in A and B
if ($seen{$_}) { delete $seen{$_} }
# it was NOT found in A
else { push @b, $_ }
}
close FIRST;
close SECOND;
@a = keys %seen;
Now you have two arrays, @a and @b, which hold the unique elements found
in each. This assumes, however, that neither file_a nor file_b contains
duplicate elements.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]