I am working out a way to store the relationships between SQL tables for quick retrival. So if I have table A and table B, I'd like to know the relationship between the two. In a pseudo-xml (working towards evovling this to RDF) I'd represent relationships thusly:

<relationships> <direct key1="csUsers.ID" key2="csUsers_lang.ID" /> <indirect key1="csUsers.ID" key2="csGroups.ID" > <direct key1="csUsers.ID" key2="csUsers_Groups.ID" /> <direct key1="csGroups.ID" key2="csUsers_Groups.ID" /> </indirect> </relationships>

I'd parse this in and cache it using Data::Dumper so I'd only have to re-parse when the data changes. The question here though is i'd want to be able to ask "how does csUsers relate to csGroups?" AND also be able to ask "how does csUsers relate to csGroups?"

So what comes to mind is a hash with two keys, which of course doesn't exist. I could nest hashes, but then that gives an order to the keys $hash{csUsers}{csGroups} is different than $hash{csGroups}{csUsers}. I can come up with arbitrary (read: alphabetic) ways to nest the hashes, but I'd rather not. Any suggestions on how to simulate a hash that takes a pair of keys in arbitraty order to return a value?


In reply to storing data via 2 sibling keys by AidanLee

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.