473,239 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,239 software developers and data experts.

multiple key value hash problem

Hi All,

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
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. my  (%hashname,$cnum,$ctotal,$count,$number,$pdb,$crossangle,$resname,$respos,$resdist,@temp);
  5. open(SP,"<packing_cluster.dat") or die "Could not open $!";
  6. while(<SP>)
  7. {
  8.     my $line1 = $_;chomp $line1;
  9.     @temp = split (/\s/,$line1);
  10.     $cnum       = $temp[1];
  11.     $ctotal     = $temp[2];
  12.     $count      = $temp[3];
  13.     $number     = $temp[4];
  14.     $pdb        = $temp[5];
  15.     $crossangle = $temp[6];
  16.     $resname    = $temp[7];
  17.     $respos     = $temp[8];
  18.     $resdist    = $temp[9];
  19.     $hashname{$number} = ($pdb,$crossangle,$resname,$respos,$resdist);
  20. }
  21. close(SP);
  22. my $cnt =0;
  23. #while (($number,$pdb) = each (%hashname))
  24. #{
  25. #    print "$number => $pdb\n";
  26. #    $cnt +=1;
  27. #}
  28. open(CG,"rmsd_cluster.dat") or die "Check relevant file";
  29. while(<CG>)
  30. {
  31.         my $line2 = $_; chomp $line2;
  32.         my @gsp   = split(/\s/,$line2);
  33.         if (exists $hashname{$gsp[5]})
  34.         {
  35.             print "$gsp[2]\t$gsp[3]\t$gsp[4]\t$gsp[5]\t$hashname{$gsp[5]}\t$gsp[7]\t$crossangle\n";
  36.             $cnt +=1;
  37.         }
  38. }
  39. #close(WRITE1);
  40. print "$cnt\n";
the problem is i am not able to print the table in desired way.
Any help will be appreciated.

Sep 19 '08 #1
3 3995
971 Expert 512MB
May we please see some sample data?

Sep 19 '08 #2
4,059 Expert 2GB
at a minimum this line looks wrong:

Expand|Select|Wrap|Line Numbers
  1. $hashname{$number} = ($pdb,$crossangle,$resname,$respos,$resdist);
you want to use square brackets to assign an array to a hash key:

Expand|Select|Wrap|Line Numbers
  1. $hashname{$number} = [$pdb,$crossangle,$resname,$respos,$resdist];
thats because its actually a reference to an array.
Sep 19 '08 #3
hi the sample data looks like

table 1

cnum ctotal count number pdb crossangle resname respos resdist
2 148 1 5265 xxx 25.3 ALA 25 6.6
2 148 2 4414 yyy 13.6 GLY 32 5.1

table 2
cnum ctotal count number pdb rmsd
2 148 1 5265 xxx 2.5
2 148 2 4414 yyy 1.3

now i am tying to merge the two table so that i can have one comple table rather than 2. I am trying to make number(table1) as key and rest column as values(table 1) and now matching the number (in table 2) and then merging the tables.

Sep 20 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Frederic | last post by:
Hi, I've a problem, I've a select tag with n items. It is build from a db request with an id, a code and a label. I need to get the id and the code when the user select a label. How can I do...
by: VBNovice05 | last post by:
I am creating a hash check for an item on a classified network. The FIPS has to be enabled and everytime my software runs I get this error : "System.InvalidOperationException: This implementation...
by: yp.yean | last post by:
Hi, I created a custom control, and encountered a dirty property value persistence problem. I created a property with a custom class type, call SQLSettings which holds the SQL connection...
by: imrantbd | last post by:
This is my first problem.Please help me. I have the following code: <head> <script language="JavaScript"> function addSrcToDestList() { destList1 = window.document.forms.destList; srcList...
by: imrantbd | last post by:
I need array type name like "destList" must use for my destlist select box,not a single name.Or need a solution to capture multiple value of "destList" select box and send all selected value in php...
by: boyindie86 | last post by:
Hi I have been dabbling with a password salted hashing scheme, so to encrpyt my passwords in my users table in mySQL the code i have done is vb.net with asp The code seems to run fine until...
by: ahmurad | last post by:
Dear all, I am fresh php programmer. I've spent much time to solve a checkbox related null value submission problem in php platform. I want to submit 4 checkbox value. if I checked all the...
by: permander kumar | last post by:
hi plz help me, i have a code in which two multiple selection dropdown list. in first list if I am select single value the data are fetch in second table on button click. but the problem is in...
by: metaphysics | last post by:
I am using a jQuery script called LocalScroll, and I have a quick problem that needs fixing. The demo for the script is here: jQuery.LocalScroll - Regular Demo, and the documentation is here: Ariel...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.