view tools/intersect.pl @ 487:5616a3d38d8e

[mq]: cross-ports
author Aleksandr Rybalko <ray@ddteam.net>
date Fri, 02 Nov 2012 15:36:00 +0200
parents ae6c0eca3e29
children
line wrap: on
line source
#!/usr/bin/perl

use strict;


my @array1 = @ARGV;
my @array2 = ();

while (<STDIN>)
{
	chomp;
	push @array2, split(/\s+/);
}


my @union = my @intersection = my @difference = ();
my %count = ();
foreach my $element (@array1, @array2) { $count{$element}++ }
foreach my $element (keys %count) 
{
	push @union, $element;
        push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element;
}

print "INTESECTION: ".join(" ", @intersection)."\n";
print "DIFFERENCE: ".join(" ", @difference)."\n";