David Newman wrote:
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.
This is probably close to what you want:
#!/usr/bin/perl
use warnings;
use strict;
use constant LEFT => 1;
use constant RIGHT => 2;
@ARGV = qw/ $Lfile $Rfile /;
my $flag = LEFT;
my %compare;
while ( <> ) {
$compare{ join ',', ( split /,/ )[ 0, 1, 2 ] } |= $flag;
$flag = RIGHT if eof;
}
@ARGV = qw/ $Lfile $Rfile /;
my ( $left, $right, $both );
while ( <> ) {
${ ( \$left, \$right, \$both )[ 0 <=> $compare{ join ',', ( split
/,/ )[ 0, 1, 2 ] } - 2 ] } .= $_;
}
print "Left:\n$left\nRight:\n$right\nBoth:\n$both\n";
__END__
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/