- 论坛徽章:
- 33
|
回复 8# papagogogo
希望可以解决你的问题.- #!/usr/bin/perl
- #
- use warnings;
- use strict;
- use Number::Range;
- use Set::Scalar;
- my $file1 = "1.file";
- my $file2 = "2.file";
- my %hash1;
- my %hash2;
- open(FILE1, "<".$file1) or die("$file1, $!\n");
- while (my $line = <FILE1>) {
- chomp $line;
- my ($key, $start, $end) = split(/\s+/, $line);
- if (defined $hash1{$key}) {
- $hash1{$key} .= ",$start..$end";
- } else {
- $hash1{$key} = "$start..$end";
- }
- }
- close(FILE1);
- open(FILE2, "<".$file2) or die("$file2, $!\n");
- while (my $line = <FILE2>) {
- chomp $line;
- my ($key, $start, $end) = split(/\s+/, $line);
- if (defined $hash2{$key}) {
- $hash2{$key} .= ",$start..$end";
- } else {
- $hash2{$key} = "$start..$end";
- }
- }
- close(FILE2);
- foreach my $key (keys %hash1) {
- my $range1 = Number::Range->new($hash1{$key});
- my $range2 = Number::Range->new($hash2{$key});
- my @number1 = $range1->range;
- my @number2 = $range2->range;
- my $set1 = Set::Scalar->new(@number1);
- my $set2 = Set::Scalar->new(@number2);
- my $setc = $set1->unique($set2);
- my $setd = $set1->difference($setc);
- print $set1, "\n";
- print $set2, "\n";
- print $setc, "\n";
- print $setd, "\n";
- }
复制代码 |
|