I have two tables of data, one contains 9 columns and another has 7 columns,
both the tables has 3 column common, now what i am trying to do is to merge the two tables in one using hash.
I used the first tables as the hash and made 4th column as the key and rest 5,6,7,8,9 as the values and now i read the another table and if the values existes then print the information from both the tables.
here is my code
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl
- use strict;
- use warnings;
- my (%hashname,$cnum,$ctotal,$count,$number,$pdb,$crossangle,$resname,$respos,$resdist,@temp);
- open(SP,"<packing_cluster.dat") or die "Could not open $!";
- while(<SP>)
- {
- my $line1 = $_;chomp $line1;
- @temp = split (/\s/,$line1);
- $cnum = $temp[1];
- $ctotal = $temp[2];
- $count = $temp[3];
- $number = $temp[4];
- $pdb = $temp[5];
- $crossangle = $temp[6];
- $resname = $temp[7];
- $respos = $temp[8];
- $resdist = $temp[9];
- $hashname{$number} = ($pdb,$crossangle,$resname,$respos,$resdist);
- }
- close(SP);
- my $cnt =0;
- #while (($number,$pdb) = each (%hashname))
- #{
- # print "$number => $pdb\n";
- # $cnt +=1;
- #}
- open(CG,"rmsd_cluster.dat") or die "Check relevant file";
- while(<CG>)
- {
- my $line2 = $_; chomp $line2;
- my @gsp = split(/\s/,$line2);
- if (exists $hashname{$gsp[5]})
- {
- print "$gsp[2]\t$gsp[3]\t$gsp[4]\t$gsp[5]\t$hashname{$gsp[5]}\t$gsp[7]\t$crossangle\n";
- $cnt +=1;
- }
- }
- #close(WRITE1);
- print "$cnt\n";
Any help will be appreciated.
Thanks
Kumar