#!/usr/local/bin/perl
$file1="path to filename1";
my $hash={};
open (File1, "<${file1}") || die "Unable to open ${file1} for reading $! \n";
while (<File1>){
chomp();
@array=split(/,/,$_);
#The below builds a referenced hash of hashes
$hash->{$array[0]}{'exists'}=1;
$hash->{$array[0]}{'description 1 test'}=$array[1];
$hash->{$array[0]}{'field 1 test'}=$array[2];
$hash->{$array[0]}{'field 2 test'}=$array[3];
.
.
.
}
#done with processing file1.
close(File1);
open (File2,"<$file2") || die "Unable to open $file2 for reading: $!\n:"
while (<File2>){
chomp();
@array=split (/,/,$_);
if (exists $hash->{$array[0]}{'exists'} and $hash->{$array[0]}{'exists'}==1){
$hash->{$array[0]}{'first field from second file'}=$array[1];
$hash->{$array[0]}{'second field'}=$array[2];
$hash->{$array[0]}{'third field'}=$array[3];
.
.
.
.
}
}
#done with processing files when there are matching keys.
close(File2);
#you now have a $hash that is a reference to hashes.
foreach $key (keys %{$hash}){
# print "$key :$hash->{$key}\n";
foreach $index (keys %{$hash->{$key}}) {
print "\$hash->{'$key'}{'$index'}=$hash->{$key}{$index}\n";
}
}
|