Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Outer Join on 2 files

by hdb (Monsignor)
on Apr 18, 2015 at 08:55 UTC ( [id://1123863]=note: print w/replies, xml ) Need Help??


in reply to Outer Join on 2 files

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...

Replies are listed 'Best First'.
Re^2: Outer Join on 2 files
by healingtao (Novice) on May 04, 2015 at 05:30 UTC

    Thanks very much to all. I used some of your ideas and got it to work

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1123863]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-25 23:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found