in reply to Merging data

Hi

I could tell you the steps how to proceed.

Step 1. Use while loop to read file 1. and store your sample names and its corresponding features through hash. If your sample names are unique then use it as a key and corresponding features as its values. Something like

my %hash1; open my $IN, "file1.txt" or die $!; my $header = <$IN>; ## use if the file has a header otherwise leave it while(<$IN>){ chomp $_; my @line = split(',',$_); ## split the line to get the sample name a +nd its values $hash1{$line[0]} = 1; ## if your first column is a sample name or ch +ange it accordingly } close($IN);

Step 2. Now open the file 2 and check for the sample names those are common to both the files using exists

my %CommonSampleNames open my $IN1, "file2.txt" or die $!; my $head = <$IN1> ;## again use it if it has a header while(<$IN1>){ chomp $_; my @line = split(',', $_); if(exists $hash1{$line[0]} ){ ## $line[0] is the sample name column $CommonSampleNames{$line[0]} = 1; } } close($IN1);

3. Open the third file or reference file and again using exists extract the corresponding names.

my %supHash open my $ref, "ref.txt" or die $!; $head = <$ref>; ## if header is present while(<$ref>){ chomp $_; my @line = split(',', $_); ## if it is a csv file if(exists $CommonSampleNames{$line[0]} ){ $supHash{$ine[0]} = $line[1]; ## if second column has reference names } } close($ref);