in reply to Re: Re: matching data with 2 files
in thread matching data with 2 files

Thanks Skeeve, moving the inside loop out worked
once i stopped confusing my key and hash values
below is the final code, a bit clinky but it works


open (LIST1, $list1) or die "cannot open $list1";
open (LIST2, $list2) or die "cannot open $list2";

my %list2key= ();
while ($line1 = <LIST1>)
{
my ($a, $b) = split(/\t/,$line1);
$list2key{$a} = $b;
}

while ($line2 = <LIST2>)
{
#get all the variables for line from LIST2

my ($a, $b, $c, $d, $e, $f) = split(/\t/,$line2);
# do you mean "\t" or \t? are there " in the file?

# This will read your second file once for the
# first line of your first file
# As soon as you have the second line of you first
# file, it will forget about the second file!
# Maybe you should move this loop out of the LIST1-loop

if (exists $list2key{$a})
{
$name = $list2key{$a};
#print out to screen as a test then to a file later
print "$name $b $c $d $e $f\n";
}
}

close LIST2;
close LIST1;