Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join Two Tables using Perl

Status
Not open for further replies.

mikawin

Technical User
Apr 15, 2009
28
0
0
US
Hello,

I have two tables of 70*10^3 and 800*10^3 rows each. I want to get data corresponding to the columns 1, 2 and 3 of the first table from the second table.

Sample Data:

Table 1
1 PQRS STUV
2 ABCD EFGH
3 HIJK LMNOP

Table 2
1 PQRS STUV 987 654 321
2 ABCD EFGH 1275 1375 76
3 HIJK LMNOP 654 321 98
....
....

Presently, I am doing it by putting each of the tables' rows in arrays and comparing and getting what I want, but find it rather tedious. Can someone suggest a better/more efficient way?

Thanks,
Mika
 
Assuming you have sufficient memory to hold it, load table 2 into a hash using the first three fields as a key (you can either concatenate them using a safe delimiter, i.e. $table2{$field1,$field2,$field3), or use a hash of a hash of a hash, i.e. $table2{$field1}{$field2}{$field3}), and then simply print out the matching values when you process table 1.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top