equal
deleted
inserted
replaced
1 #! perl -w |
1 #! perl -w |
|
2 # Copyright (c) 2009 Symbian Foundation Ltd |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of the License "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Symbian Foundation Ltd - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # Compares two files |
|
15 |
2 use strict; |
16 use strict; |
3 |
17 |
4 my $element; |
18 my $element; |
5 my @union = (); |
19 my @union = (); |
6 my @intersection = (); |
20 my @intersection = (); |
7 my @difference = (); |
21 my @difference = (); |
8 my %count = (); |
22 my %count = (); |
9 |
23 |
10 my $file1 = shift or die "Usage: $0 file1 file2\n"; |
24 my $file1 = shift or die "Usage: $0 file1 file2 | optional -I[ntersection]\n"; |
11 my $file2 = shift or die "Usage: $0 file1 file2\n"; |
25 my $file2 = shift or die "Usage: $0 file1 file2 | optional -I[ntersection]\n"; |
12 |
26 my $mode = shift; |
13 open FILE1, "<$file1" or die "ERROR: Can't read $file1"; |
27 open FILE1, "<$file1" or die "ERROR: Can't read $file1"; |
14 open FILE2, "<$file2" or die "ERROR: Can't read $file2"; |
28 open FILE2, "<$file2" or die "ERROR: Can't read $file2"; |
15 |
29 |
16 my @file1_content = <FILE1>; |
30 my @file1_content = <FILE1>; |
17 my @file2_content = <FILE2>; |
31 my @file2_content = <FILE2>; |
24 foreach $element (keys %count) { |
38 foreach $element (keys %count) { |
25 push @union, $element; |
39 push @union, $element; |
26 push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element; |
40 push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element; |
27 } |
41 } |
28 |
42 |
29 if (@difference > 0) { |
43 if (!defined $mode) { |
30 foreach (@difference){ |
44 if (@difference > 0) { |
31 print $_; |
45 foreach (@difference){ |
32 } |
46 print $_; |
|
47 } |
|
48 } else { |
|
49 print "* Files are identical\n"; |
|
50 } |
|
51 } elsif ($mode eq "-I") { |
|
52 if (@intersection > 0) { |
|
53 foreach (@intersection){ |
|
54 print $_; |
|
55 } |
|
56 } |
33 } else { |
57 } else { |
34 print "* Files are identical\n"; |
58 print "Usage: $0 file1 file2 | optional -I[ntersection]\n"; |
35 } |
59 } |