I have a problem when pairs of numbers are matched with other pairs of numbers. For example, (1,2) β (12,97). Some pairs can display several other pairs, so I really need the ability to map a pair to a list of lists, for example (1,2) β ((12,97), (4,1)). At the end of the day, I want to separately process each of the values ββ(i.e., each list of lists).
In Python, I could do this by simply saying:
key = ( x, y )
val = [ a, b ]
if (x,y) not in my_dict:
my_dict[ (x,y) ] = []
my_dict[ (x,y) ].append( [a,b] )
However, in Perl, I have to use refs for keys and values. Therefore, I can say:
$keyref = [ x1, y1 ]
$valref = [ a, b ]
%my_hash = { $keyref => $valref }
But what happens when another pair (x2, y2) arrives? Even if x2 == x1 and y2 == y1, $ keyref = [x2, y2] will be different from the previous generated keyref, so I donβt see a way to do the search. Of course, I could compare (x2, y2) with each dereferenced hash key, but in the end God gave us hash tables to avoid having to do this.
Is there a Perl solution?
Thank,
-W.