Another option would be to use Bio::Coordinate::Graph, it's part of the BioPerl package of Perl Modules. It uses Djikstra's algorithm to solve the shortest path problem, and you just need to provide a hash of hashes for it to compute the paths, like this:
# this hash represents a directed graph with vertices {A,B,C,D,E} and # these edges: # A -> B (weight = 3) # B -> D (weight = 1) # B -> C (weight = 1) # D -> E (weight = 1) my $hash= { 'A' => { 'B' => 3 }, 'B' => { 'D' => 1, 'C' => 1 }, 'C' => undef, 'D' => { 'E' => 1 }, 'E' => undef }; my $graph = Bio::Coordinate::Graph->new(-graph => $hash); my @node_names = shortest_path( 'A', 'E' ); # node_names now contains a list of the vertex names that make up the # shortest path (A,B,D,E)
So, in the context of your question you could build a hash of hashes as above, where the node names are SQL table names and there is a path from A->B if there is a foreign key relationship between tables A and B.

Hope this helps. :)

In reply to Re: Path computation for SQL generation by biosysadmin
in thread Path computation for SQL generation by dragonchild

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.