in reply to (Ovid) Re: array reference as hash key
in thread array reference as hash key

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.