I know this is an old thread, but I thought I'd answer the question (why would you want to use a reference as a hash key) anyway.

In my case I want to use a hash reference as a key to another hash so I can link two different hashes together w/o duplicating the keys repeatedly in the other hash. I have a doubly linked hash (a->b and b<-a) and I also have large keys for each hash so I don't want to duplicate them repeatedly.

Consider the case of processing student enrollment data. In one hash I want to link each occurrence of a student (the key) to the list of classes he took (the value: an anonymous hash w/ the class name as the key and the grade as the value). I also want to link the opposite way in another hash where the class name is the key and the value is an anonymous hash with the student name as key and the grade as the value. Since all my keys are large text strings (student name or class name), I would prefer to store a reference to the opposing hash rather than the key itself.


In reply to Re^2: array reference as hash key by Anonymous Monk
in thread array reference as hash key by smgfc

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.