equal
deleted
inserted
replaced
5 my @union = (); |
5 my @union = (); |
6 my @intersection = (); |
6 my @intersection = (); |
7 my @difference = (); |
7 my @difference = (); |
8 my %count = (); |
8 my %count = (); |
9 |
9 |
10 my $file1 = shift or die "Usage: $0 file1 file2\n"; |
10 my $file1 = shift or die "Usage: $0 file1 file2 | optional -I[ntersection]\n"; |
11 my $file2 = shift or die "Usage: $0 file1 file2\n"; |
11 my $file2 = shift or die "Usage: $0 file1 file2 | optional -I[ntersection]\n"; |
12 |
12 my $mode = shift; |
13 open FILE1, "<$file1" or die "ERROR: Can't read $file1"; |
13 open FILE1, "<$file1" or die "ERROR: Can't read $file1"; |
14 open FILE2, "<$file2" or die "ERROR: Can't read $file2"; |
14 open FILE2, "<$file2" or die "ERROR: Can't read $file2"; |
15 |
15 |
16 my @file1_content = <FILE1>; |
16 my @file1_content = <FILE1>; |
17 my @file2_content = <FILE2>; |
17 my @file2_content = <FILE2>; |
24 foreach $element (keys %count) { |
24 foreach $element (keys %count) { |
25 push @union, $element; |
25 push @union, $element; |
26 push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element; |
26 push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element; |
27 } |
27 } |
28 |
28 |
29 if (@difference > 0) { |
29 if (!defined $mode) { |
30 foreach (@difference){ |
30 if (@difference > 0) { |
31 print $_; |
31 foreach (@difference){ |
32 } |
32 print $_; |
|
33 } |
|
34 } else { |
|
35 print "* Files are identical\n"; |
|
36 } |
|
37 } elsif ($mode eq "-I") { |
|
38 if (@intersection > 0) { |
|
39 foreach (@intersection){ |
|
40 print $_; |
|
41 } |
|
42 } |
33 } else { |
43 } else { |
34 print "* Files are identical\n"; |
44 print "Usage: $0 file1 file2 | optional -I[ntersection]\n"; |
35 } |
45 } |