Hi
Whatever the above you use, you need to have a concept. Databases are doing this type of joins with two basic algorithms: sort merge or nested loop.
The nested loop works the following way:
- Loop around one of the table.
- Set up the key made of your 3 columns.
- Loop around the second table and merge the rows each time the key match.
- Move to the next row of the first table and repeat the process.
I do not recommend this algorithm because it has an awful performance impact. Actually it is one of two ways to take down a server for a couple of hours or weeks!
The second way to do it is called sort merge:
- Sort file A on all 3 columns of your key in ascending way. Eventually use the sort command of the OS. It will use less RAM and be probably faster.
- Sort file B exactly the same way.
- Retrieve the first row of file A.
- Check if the keys of the first row of file B match. They should.
- Work yourself down file B as long as the keys match.
- When the keys in B do not match any more, move to the next row of A.
- Start at the same position in B and work yourself down as long as keys match.
- ...
The above assumes one of both file has only one row per composite key ( your 3 columns). If this is the case you will process both files only once and your files are merged. If you have a so called many to many relation between the keys of your two files, you will have to work down file B several times.
I recommend you start merging the two smallest files first, then you sort the result and add the next file with a new merge.
Eventually search CPAN or the net for sort merge examples or modules.
K
The best medicine against depression is a cold beer!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.