- 论坛徽章:
- 32
|
本帖最后由 yestreenstars 于 2014-07-28 15:39 编辑
如果是Cygwin的话就用这个,我不明白为什么Cygwin下用given语句会报错,有人知道吗?- #!perl
- use warnings;
- use strict;
- sub JiaoJi {
- return 2 if $_[0][0] <= $_[1][0] && $_[0][1] >= $_[1][1] || $_[0][0] >= $_[1][0] && $_[0][1] <= $_[1][1];
- return ($_[0][1] - $_[1][0] > 2) ? 2 : 0 if $_[0][0] <= $_[1][0] && $_[0][1] <= $_[1][1];
- return ($_[1][1] - $_[0][0] > 2) ? 2 : 1 if $_[0][0] >= $_[1][0] && $_[0][1] >= $_[1][1];
- }
- open(FILE1, 'data1.txt') or die;
- open(FILE2, 'data2.txt') or die;
- my(%hash1, %hash2);
- while(<FILE1>){
- chomp;
- @_ = split /[:-]/;
- push(@{$hash1{$_[0]}}, [$_[1], $_[2]]);
- }
- while(<FILE2>){
- chomp;
- @_ = split /[:-]/;
- push(@{$hash2{$_[0]}}, [$_[1], $_[2]]);
- }
- close(FILE1);
- close(FILE2);
- for my $key (keys %hash1){
- while(@{$hash1{$key}}){
- while(@{$hash2{$key}}){
- unless(@{$hash1{$key}}){
- open(OUTPUT_FILE, '>>data2_diff.txt');
- printf OUTPUT_FILE "%s:%d-%d\n", $key, $_->[0], $_->[1] for @{$hash2{$key}};
- undef @{$hash2{$key}};
- close(OUTPUT_FILE);
- last;
- }
- my $result = JiaoJi($hash1{$key}[0], $hash2{$key}[0]);
- if($result == 0){
- open(OUTPUT_FILE, '>>data1_diff.txt');
- print OUTPUT_FILE "$key:$hash1{$key}[0][0]-$hash1{$key}[0][1]$/";
- shift @{$hash1{$key}};
- }elsif($result == 1){
- open(OUTPUT_FILE, '>>data2_diff.txt');
- print OUTPUT_FILE "$key:$hash2{$key}[0][0]-$hash2{$key}[0][1]$/";
- shift @{$hash2{$key}};
- }else{
- open(OUTPUT_FILE, '>>data_comm.txt');
- print OUTPUT_FILE "$key:$hash1{$key}[0][0]-$hash1{$key}[0][1] $hash2{$key}[0][0]-$hash2{$key}[0][1]$/";
- shift @{$hash1{$key}};
- shift @{$hash2{$key}};
- }
- close(OUTPUT_FILE);
- }
- open(OUTPUT_FILE, '>>data1_diff.txt');
- printf OUTPUT_FILE "%s:%d-%d\n", $key, $_->[0], $_->[1] for @{$hash1{$key}};
- undef @{$hash1{$key}};
- close(OUTPUT_FILE);
- }
- }
复制代码 |
|