equal
deleted
inserted
replaced
|
1 #! perl -w |
|
2 use strict; |
|
3 |
|
4 my $element; |
|
5 my @union = (); |
|
6 my @intersection = (); |
|
7 my @difference = (); |
|
8 my %count = (); |
|
9 |
|
10 my $file1 = shift or die "Usage: $0 file1 file2\n"; |
|
11 my $file2 = shift or die "Usage: $0 file1 file2\n"; |
|
12 |
|
13 open FILE1, "<$file1" or die "ERROR: Can't read $file1"; |
|
14 open FILE2, "<$file2" or die "ERROR: Can't read $file2"; |
|
15 |
|
16 my @file1_content = <FILE1>; |
|
17 my @file2_content = <FILE2>; |
|
18 |
|
19 close FILE1; |
|
20 close FILE2; |
|
21 |
|
22 print "* Comparing $file1 and $file2\n"; |
|
23 foreach $element (@file1_content, @file2_content) { $count{$element}++ } |
|
24 foreach $element (keys %count) { |
|
25 push @union, $element; |
|
26 push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element; |
|
27 } |
|
28 |
|
29 if (@difference > 0) { |
|
30 foreach (@difference){ |
|
31 print $_; |
|
32 } |
|
33 } else { |
|
34 print "* Files are identical\n"; |
|
35 } |