37,741
社区成员
发帖
与我相关
我的任务
分享
#!/usr/bin/env perl
#
use strict;
use warnings;
my $old = shift @ARGV;
my $new = shift @ARGV;
my %hash;
sub do_disp {
my $hash = shift;
for my $key (keys %$hash) {
my $array = $$hash{$key};
print "$key => ";
for my $suba (@$array) {
print "[@$suba] ";
}
print "\n";
}
}
sub do_hash {
my $file = shift;
open my $FD, $file or die $!;
while (<$FD>) {
chomp;
next if !/^\d+/;
my ($id, $pos, $ctx) = split;
if ($hash{$id}) {
push $hash{$id}, [$pos, $ctx];
}
else {
$hash{$id} = [[$pos, $ctx]];
}
}
close $FD;
}
do_hash($old);
do_disp(\%hash);
print '=' x 80, "\n";
do_hash($new);
do_disp(\%hash);