473,545 Members | 2,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiple key value hash problem

55 New Member
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 4014
eWish
971 Recognized Expert Contributor
May we please see some sample data?

--Kevin
Sep 19 '08 #2
KevinADC
4,059 Recognized Expert Specialist
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
kumarboston
55 New Member
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
3410
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 that without doing an other request to database ? Can I use array as value attribute of option tag ? Thanks
0
909
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 is not part of the Windows Platform FIPS validated cryptographic algorithms. " I used System.Security.Cryptography.MD5CryptoServiceProvider. ...
0
1223
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 parameters, the class as follows: public sealed class SQLSettings { private string serverName;
3
12540
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 = window.document.forms.srcList;
3
8703
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 page.The multiple select value then insert in database added by comma.The following is my code: Form Page:form.php <head> <script...
0
1291
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 I try to execute the query and it throws the following exception at the line
2
2377
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 checkbox, all the checked value is submitted properly. if checked any checkbox , the corresponding checkbox value is submitted properly. But I need to...
2
1809
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 first dropdown list the second field is also select after the page submit. the code is <?php include("connect.php"); ?> <html><body>
0
3340
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 Flesler: jQuery.LocalScroll. The Local Scroll script uses the toScroll and jQuery scripts to function. I don't really understand what "hash" means,...
0
7490
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7682
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7935
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7449
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6009
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.