http://qs321.pair.com?node_id=494288

ch1 has asked for the wisdom of the Perl Monks concerning the following question:

I trying to join two files on a common field.
File one:
upc,qty
840197083284,2
840197083291,3
840197083307,21
840197083314,0
File two:
product_sku,size,color,upc
121,MD,Black,840197083277
121,LG,Black,840197083284
121,XL,Black,840197083291
121,2XL,Black,840197083307

I'm trying to join on upc.
I've read a number of post.... combining 2 files with a comon field which seems to be close but I can't make it work.

Update: I'm new to perl and to perlmonks... So, First thanks for all the help. Here is the code that worked for me.
open(I1,"Inventory.csv") or die "file1: $!"; $_ = <I1>; # read column headings while (<I1>) { # get data chomp; my ($upc,$qty) = split /,/; $data{$upc} = $qty; } open(I2,"Matrix.csv") or die "file2: $!"; $_ = <I2>; # read column headings while (<I2>) { # get data chomp; my ($sku,$siz,$clr,$upc) = split /,/; $data{$upc} .= join ',', '', $sku, $siz, $clr; } open(my $fh_out, '>', 'new.csv') or die("Can't open output file: $!\n"); for (sort keys %data) { my @content = "$data{$_},$_"; if (grep(/.*,.*,.*,.*$/, @content)){@column = grep(/.*,.*,.*,.*$/, + @content)}; #@column = grep(/.*,.*,.*,.*$/, @content); print $fh_out "@column\n"; }

Edit: g0n - Linkified PM link