-
Notifications
You must be signed in to change notification settings - Fork 4
/
Diff.perl
executable file
·91 lines (84 loc) · 1.85 KB
/
Diff.perl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl
use lib ("$ENV{HOME}/lookup", "$ENV{HOME}/lib64/perl5", "/home/audris/lib64/perl5","$ENV{HOME}/lib/perl5", "$ENV{HOME}/lib/x86_64-linux-gnu/perl", "$ENV{HOME}/share/perl5");
use strict;
use warnings;
sub ltrim { my $s = shift; $s =~ s/^\s+//; return $s }
open A, "zcat $ARGV[0]|";
open B, "zcat $ARGV[1]|";
my $pa = "";
my $pb = "";
my %v = ();
my %v1 = ();
my %tmpa = ();
my %tmpb = ();
my $vala = readPieceA ();
my $valb = readPieceB ();
my $la = 0;
my $lb = 0;
while ($vala){
if ($pa eq $pb){
for my $k (keys %v){
print "$pa;$k\n" if !defined $v1{$k};
}
%v = ();
for my $k (keys %tmpa){ $v{$tmpa{$k}}++; $pa = $k; };
%v1 = ();
for my $k (keys %tmpb){ $v1{$tmpb{$k}}++; $pb = $k; };
%tmpb = ();
%tmpa = ();
$vala = readPieceA ();
$valb = readPieceB ();
}else{
my $pa0 = ltrim ($pa);
my $pb0 = ltrim ($pb);
if (($pa0 cmp $pb0) < 0){
#print "$la:$lb: whole:$pa:$pb:\n";
for my $k (keys %v){
print "$pa;$k\n";
}
%v = ();
for my $k (keys %tmpa){ $v{$tmpa{$k}}++; $pa = $k; };
%tmpa = ();
$vala = readPieceA ();
}else{
#bad sort,
for my $k (keys %v){
print "$pa;$k\n";
}
%v = ();for my $k (keys %tmpa){ $v{$tmpa{$k}}++; $pa = $k; };%tmpa = ();
$vala = readPieceA ();
#print STDERR "cant happen :$la:$lb:\n";
#exit ();
}
}
}
sub readPieceA {
while (<A>){
$la++;
chop();
$_ =~ m/^([^;]*);(.*)/;
my ($a, $b) = ($1, $2);
if ($pa ne "" && $a ne $pa){
$tmpa{$a} = $b;
return 1;
}
$v{$b}++;
$pa = $a;
}
return 0;
}
sub readPieceB {
while (<B>){
$lb++;
chop();
$_ =~ m/^([^;]*);(.*)/;
my ($a, $b) = ($1, $2);
if ($pb ne "" && $a ne $pb){
$tmpb{$a} = $b;
return 1;
}
$v1{$b}++;
$pb = $a;
}
return 0;
}