冬休みの宿題か?
#!/usr/bin/perl
use strict;
use warnings;
use IO::File;
my %data1= parse('data1.txt');
my %data2= parse('data2.txt');
my @keys= unique( keys %data1, keys %data2 );
my $fh= new IO::File('data3.txt','>');
for( sort @keys ){
my $key= $_;
my @data1= @{ $data1{$key} || [] };
my @data2= @{ $data2{$key} || [] };
print $fh join(',',map {nval($_)} ($key,@data1[1..2],@data2[0..2]))."\n";
}
sub nval{defined $_[0] ? $_[0] : ''}
sub unique{my %t;grep !$t{$_}++,@_}
sub parse {
my $file= shift;
my $fh= new IO::File( $file ) || die("$file:$!");
my %r= ();
while(<$fh>){
chomp();
my @data = split /,/,$_;
$r{ $data[0] }= \@data;
}
return wantarray ? %r : \%r;
}