in reply to optimal way of comparing 2 arrays
Prints:my @file1 = qw{1 2 3 4 }; my @file2 = qw{ 2 3 4 5}; my %seen; my @fa =([1<<1,\@file1,'File-1 only'],[1<<2,\@file2,'File-2 only'], [1<<1|1<<2,[],'Both have']); for (@fa){ my ($v,$f)=@$_; $seen{$_} |= $v for @$f }; ## print Dumper \%seen; for (@fa){ my ($v,$f,$n)=@$_; $v==$seen{$_} and print qq[$n :$_\n] for sort keys %seen }
Update: Updated code to also print "Both" lines.File-1 only :1 File-2 only :5 Both have :2 Both have :3 Both have :4
"Man cannot live by bread alone...
He'd better have some goat cheese and wine to go with it!"
|
|---|