Could not resist, here is a column index driven approach.
use strict; use warnings; use Data::Dumper; my $data1 = <<EO1; 38375U|36182D|36182D1|HMAG|HMBSWEE|20150416|mortgage 383333|361333|3618333|HABS|HABSDDE|20150330|mortgage2 EO1 my $data2 = <<EO2; 38375U|3DD82D|36FF333|HMAG|HMBSWEE|9010|765423|364633|46566 38EE33|361DD3|36LLE33|H99S|HAOOODE|2330|377233|347433|34488 EO2 sub process_file { my ( $file, $keys, $in, $out, $hash ) = @_; open my $fh, "<", $file; while(<$fh>) { chomp; my @attr = split /[|]/; @{ $hash->{join '|', @attr[@$keys]} }[ @$out ] = @attr[ @$in ]; } close $fh; } my %result; process_file( \$data1, [0,3,4], [0..6], [0..6], \%result ); process_file( \$data2, [0,3,4], [0,3,4,5..8], [0,3,4,7..10], \%result +); print Dumper \%result;
Dealing with ignoring the header line and printing is left as an exercise...
In reply to Re: Outer Join on 2 files
by hdb
in thread Outer Join on 2 files
by healingtao
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |