my $Usage = "Usage: $0 file1 file2 > combined.file\n"; die $Usage unless ( @ARGV == 2 and -f $ARGV[0] and -f $ARGV[1] ); my ($inf1,$inf2) = @ARGV; #### open( IN1, $inf1 ) or die "Can't open $inf1: $!"; #### my %file1; while () { next unless (/.:./); # maybe warnings aren't needed here chomp; my ($key,$val) = split( /:/, $_, 2 ); if ( $key =~ /^\s*$/ ) { warn "$inf1:$.:Empty key field\n"; next; } if ( exists( $file1{$key} )) { warn "$inf1:$.:Duplicate key string\n"; next; # might want to say more about that } # might want to check $val too... # get here if everything's okay: $file1{$key} = $val; } close IN1; #### open( IN2, $inf2 ) or die "Can't open $inf2: $!"; while () { next unless ( /.:./ ); my ($key,$val) = split( /:/, $_, 2 ); # error checking similar to what was done for $inf1 # ... # if $key did not occur in $inf1, and if this means that you # don't want to list it in the final output, then don't put # it into the hash in the first place unless ( exists( $file1{$key} )) { warn "$inf2:$.:Key $key not found in $inf1\n"; next; } $file1{$key} .= ";$val"; } close IN2; #### perl_script infile.a infile.b > outfile 2> script.errs