Greetings. I'm looking to compare two contact lists in csv format, and
then print out "here are the records in in Llist only, in Rlist only,
and what's in common."
I should compare only 3 of the 82 fields in each list. There are
differences in some of the other fields that I should ignore.
If I read in each csv file as an array, List::Compare does a nice job of
comparing all 82 fields as a single array element. But I should only
look at 3 fields, not all 82. (snippet A below)
I can also use List::Compare plus a split function to strip out just the
3 fields I'm comparing. However, the resuling arrays then only have
three fields in each array element. (snippet B below)
How to compare only selected fields in each list, but then present all
fields for any matches?
thanks
dn
SNIPPET A
open(DAT, $Rfile) or die("unable to open");
# here, each line has 82 fields
my @Llist = <DAT>;
}
close(DAT);
# yes, it's stupid that this repeats
open(DAT, $Rfile) or die("unable to open");
my @Rlist = <DAT>;
}
close(DAT);
$lc = List::Compare->new([EMAIL PROTECTED], [EMAIL PROTECTED]);
@Lonly = $lc->get_unique;
@Ronly = $lc->get_complement;
@intersection = $lc->get_intersection;
# each line still has 82 fields
SNIPPET B
open(DAT, $Lfile) or die("unable to open");
foreach $line (<DAT>) {
($FirstName,
$LastName,
$Company) = split ',', $line;
$compCriteria = $FirstName . "," . $LastName . "," . $Company;
# here, each line has 1 field, concatenated from 3
push (@Lcomp, $compCriteria);
}
close(DAT);
# get files
open(DAT, $Rfile) or die("unable to open");
foreach $line (<DAT>) {
($FirstName,
$LastName,
$Company) = split ',', $line;
$compCriteria = $FirstName . "," . $LastName . "," . $Company;
push (@Rcomp, $compCriteria);
}
close(DAT);
# find and print common entries
$lc = List::Compare->new([EMAIL PROTECTED], [EMAIL PROTECTED]);
@Lonly = $lc->get_unique;
@Ronly = $lc->get_complement;
@intersection = $lc->get_intersection;
# each line has 1 field, concatenated from 3
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/