Add intersection option for difflist.pl
authorShabeR@UK-SHABER
Mon, 20 Apr 2009 16:26:33 +0100
changeset 64 3554074ceb34
parent 63 f5604d0e720a
child 65 0099c046d4f3
Add intersection option for difflist.pl
common/tools/difflist.pl
--- a/common/tools/difflist.pl	Thu Apr 16 12:14:09 2009 +0100
+++ b/common/tools/difflist.pl	Mon Apr 20 16:26:33 2009 +0100
@@ -7,9 +7,9 @@
 my @difference = ();
 my %count = ();
 
-my $file1 = shift or die "Usage: $0 file1 file2\n";
-my $file2 = shift or die "Usage: $0 file1 file2\n";
-
+my $file1 = shift or die "Usage: $0 file1 file2 | optional -I[ntersection]\n";
+my $file2 = shift or die "Usage: $0 file1 file2 | optional -I[ntersection]\n";
+my $mode  = shift;
 open FILE1, "<$file1" or die "ERROR: Can't read $file1";
 open FILE2, "<$file2" or die "ERROR: Can't read $file2";
 
@@ -26,10 +26,20 @@
     push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element;
 }
 
-if (@difference > 0) {
-    foreach (@difference){
-        print $_;
-    }
+if (!defined $mode) {
+	if (@difference > 0) {
+		foreach (@difference){
+			print $_;
+		}
+	} else {
+		print "* Files are identical\n";
+	}
+} elsif ($mode eq "-I") {
+	if (@intersection > 0) {
+		foreach (@intersection){
+			print $_;
+		}
+	}
 } else {
-    print "* Files are identical\n";
+	print "Usage: $0 file1 file2 | optional -I[ntersection]\n";
 }