-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfldiff
More file actions
executable file
·94 lines (79 loc) · 1.5 KB
/
fldiff
File metadata and controls
executable file
·94 lines (79 loc) · 1.5 KB
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
91
92
93
#!/usr/bin/perl -w
use strict;
my $sep = 'VS';
# Utility to diff two lists of files
# Example usage:
# fldiff `grep Argpass * | cut -d: -f1 | uniq` VS `ls *.pm`
# That'd find all .pm files that don't have the text "Argpass" in them...
main();
############################
sub main
{
my @args = @ARGV;
my ($list1, $list2) = get_lists_from_args(@args);
sorted_compare($list1, $list2);
}
sub usage
{
die "usage: fldiff FILES1.. $sep FILES2..\n\tFiles in list delimited by spaces\n";
}
sub get_lists_from_args
{
my (@args) = @_;
my @lists;
my $clist = 0;
foreach my $arg (@args)
{
if($arg eq $sep)
{$clist++;next;}
push(@{$lists[$clist]}, $arg);
}
if( (! $lists[1]) || (! $lists[0]))
{usage();}
my @l1 = sort @{$lists[0]};
my @l2 = sort @{$lists[1]};
return(\@l1, \@l2);
}
sub sorted_compare
{
my($l1, $l2) = @_;
# my @onlyl1;
# my @onlyl2;
while(@$l1 && @$l2)
{ # Easy to compare two nonempty lists
my $versus = $$l1[0] cmp $$l2[0];
if($versus == 0)
{ # Same element in each, quietly remove
splice(@$l1, 0, 1);
splice(@$l2, 0, 1);
}
elsif($versus < 0) # First list is first
{
my $just1 = splice(@$l1, 0, 1);
# push(@onlyl1, $just1);
print "<$just1\n";
}
else # $versus > 0, second list is first
{
my $just2 = splice(@$l2, 0, 1);
# push(@onlyl2, $just2);
print ">$just2\n";
}
}
if(@$l1)
{
foreach my $flentry (@$l1)
{
# push(@onlyl1, $flentry);
print "<$flentry\n";
}
}
if(@$l2)
{
foreach my $flentry (@$l2)
{
# push(@onlyl2, $flentry);
print ">$flentry\n";
}
}
}