$_ = <I1>; # read column headings my @columns= split /,/;
use strict; my %data; open(I1,"file1") or die "file1: $!" $_ = <I1>; # read column headings my @columns= split /,/; my %line; while (<I1>) { # get data chomp; @line{@column} = split /,/; $data{$line{'upc'}} = $line{'qty'}; } open(I2,"file2") or die "file2: $!" $_ = <I2>; # read column headings my @columns= split /,/; while (<I2>) { # get data chomp; @line{@column} = split /,/; $data{$line{'upc'}} .= join ',',@line{@columns},''; # or: $data{$line{'upc'}} = join ',', $data{$line{'upc'}},@line{@colum +ns}; } for (sort keys %data) { print $data{$_}\n"; }
In reply to Re^2: Joining two files on common field
by Skeeve
in thread Joining two files on common field
by ch1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |