I have a file that contains relational information for a database schema that I am working with and the file is in the following format. Each line has two tables and the keys they join on. (table 1 contains key 1 and table 2 contains key 2, table 1 and table 2 join on key 1 and key 2)

Example file table 1 table 2 key 1 key 2 ------- ------- ----- ----- apple bug unid1 unid2 apple cat unid1 unid3 bug dog unid2 unid4 apple dog unid1 unid4

The above is a very generic example of the format i am dealing with and my goal is the create a perl script the will allow me to specify two table names and then the script will output how they join.

Example 1: [dmathis@wildman dmathis]$ ./script apple bug The output: apple a join bug b on a.unid1 = b.unid2
Example 2: [dmathis@wildman dmathis]$ ./script apple dog The output: Option 1: apple a join bug b on a.unid1 = b.unid2 join dog d on b.unid2 = d.unid4 Option 2: apple a join dog d on a.unid1 = d.unid4

As you can see apple and dog don't join directly to each other in one scenario, but instead through bug. This has the potential to become very complex as with a bigger more complex example there would be multiple paths from table to table and I have no idea where to start. I have been brainstorming for a couple of weeks now but have come up fruitless so far.

Does anyone have any suggestions or modules that might help me?

Best Regards

David

After all this is over, all that will really have mattered is how we treated each other.

In reply to Advise on sql table mapping. by dbmathis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.