in reply to Re: Merging larges files by columns
in thread Merging larges files by columns
I was about to post my very similar code. I would point out that if you are new to perl and not set in your ways, try to use lexical file handles as in my example as opposed to barewords.
use autodie; open (my $out, '>', 'outfile.csv'); open (my $in1, '<', 'infile1.csv'); open (my $in2, '<', 'infile2.csv'); while ( defined (my $line = <$in1>) ) { chomp $line; print {$out} $line; chomp(my $in2_line = <$in2>); my @f = split m/,/, $in2_line; print {$out} ',' . $f[1] . "\n"; } close $in1; close $in2; close $out;
|
|---|