- 论坛徽章:
- 5
|
小伙伴们 ~ {:2_168:}
若在代码试用过程中有任何不适, 请即时停用..
回复 25# newfinder - #!/usr/bin/perl
- # input files, and output files
- my @input = qw[data1.txt data2.txt];
- my @output = qw[diff1.txt diff2.txt comm.txt];
- my @files = map { open my $f, '>', $_; $f } @output;
- my %data;
- for my $i ( 0 .. 1 ) {
- @ARGV = shift @input;
- while (<>) {
- chomp;
- my ( $r, $R ) = split /:/;
- push @{ $data{$r}[$i] }, $R;
- }
- }
- my @range = map { $_->[1] } sort { $a->[0] <=> $b->[0] }
- map { [ /(\d+)/, $_ ] } keys %data;
- for my $r (@range) {
- my ( $begin, $B, %com ) = ( 0, $data{$r}[1] );
- my @B = map [ split /-/ ], @$B;
- for my $A ( @{ $data{$r}[0] } ) {
- my @A = split /-/, $A;
-
- for my $i ( $begin .. $#B ) {
- $B[$i][1] <= $A[0] and next;
- $B[$i][0] >= $A[1] and do { $begin = $i; last };
- $B[$i][1] >= $A[1]
- ? $B[$i][0] <= $A[0] || $A[1] - $B[$i][0] > 2
- : $B[$i][0] >= $A[0] || $B[$i][1] - $A[0] > 2
- and print { $files[2] } "$r:$A $B->[$i]$/"
- and ( $com{0}{$A}, $com{1}{ $B->[$i] } ) = (undef) x 2;
- $B[$i][1] >= $A[1] and do { $begin = $i; last }
- }
- }
- for my $n ( 0 .. 1 ) {
- for ( @{ $data{$r}[$n] } ) {
- exists $com{$n}{$_} or print { $files[$n] } "$r:$_$/";
- }
- }
- }
复制代码 |
|