author | dario |
Wed, 06 May 2009 18:02:34 +0100 | |
changeset 183 | 8025a9486931 |
parent 39 | 9edae8fe1416 |
child 64 | 3554074ceb34 |
permissions | -rw-r--r-- |
39
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
1 |
#! perl -w |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
2 |
use strict; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
3 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
4 |
my $element; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
5 |
my @union = (); |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
6 |
my @intersection = (); |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
7 |
my @difference = (); |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
8 |
my %count = (); |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
9 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
10 |
my $file1 = shift or die "Usage: $0 file1 file2\n"; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
11 |
my $file2 = shift or die "Usage: $0 file1 file2\n"; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
12 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
13 |
open FILE1, "<$file1" or die "ERROR: Can't read $file1"; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
14 |
open FILE2, "<$file2" or die "ERROR: Can't read $file2"; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
15 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
16 |
my @file1_content = <FILE1>; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
17 |
my @file2_content = <FILE2>; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
18 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
19 |
close FILE1; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
20 |
close FILE2; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
21 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
22 |
print "* Comparing $file1 and $file2\n"; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
23 |
foreach $element (@file1_content, @file2_content) { $count{$element}++ } |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
24 |
foreach $element (keys %count) { |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
25 |
push @union, $element; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
26 |
push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
27 |
} |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
28 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
29 |
if (@difference > 0) { |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
30 |
foreach (@difference){ |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
31 |
print $_; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
32 |
} |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
33 |
} else { |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
34 |
print "* Files are identical\n"; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
35 |
} |