473,399 Members | 4,177 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,399 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";
  41.  
the problem is i am not able to print the table in desired way.
Any help will be appreciated.

Thanks
Kumar
Sep 19 '08 #1
3 4000
eWish
971 Expert 512MB
May we please see some sample data?

--Kevin
Sep 19 '08 #2
KevinADC
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.

thanks
kumar
Sep 20 '08 #4

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

Similar topics

8
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...
0
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...
0
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...
3
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...
3
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...
0
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...
2
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...
2
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.