Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Intersection of hash keys?

121 views
Skip to first unread message

Pinkerbot

unread,
Feb 10, 2011, 10:21:33 AM2/10/11
to
Hi all,

I am trying to figure out how to compute the intersection of an
unknown number of sets, realized as key => value pairs in a hash. More
explicitly, given a hash:

%hash = (
key1 => 'value1',
key1 => 'value1',

key2 => 'value2',
key3 => 'value3',
);

Pinkerbot

unread,
Feb 10, 2011, 10:37:32 AM2/10/11
to
Sorry - somehow i posted before i was done ...
Anyhow, given a hash, e.g.:

%hash = (
key1 => 'value1',

key2 => 'value1',
key2 => 'value2',
key1 => 'value3',
key2 => 'value3',
key3 => 'value3'
);

For such a hash, we can percieve it as a set of sets, where a set
'name' is given by the value. Thus, for the hash above, we would have
3 sets (value1, value2 and value3). Now, i would like to compute the
intersection of the members of these sets (in this case, the
intersection would have 1 member, namely key2). One of the problems is
that i do not have an a priori knowledge of the number of sets to
compare.
I have looked at List::Compare, which i believe could be useful, but i
haven't found a solution yet :(

Please, any help would be highly appreciated!
Best, Tine

$Bill

unread,
Feb 10, 2011, 10:54:33 AM2/10/11
to
On 2/10/2011 7:37 AM, Pinkerbot wrote:
> Sorry - somehow i posted before i was done ...
> Anyhow, given a hash, e.g.:
>
> %hash = (
> key1 => 'value1',
> key2 => 'value1',
> key2 => 'value2',
> key1 => 'value3',
> key2 => 'value3',
> key3 => 'value3'
> );
>
> For such a hash, we can percieve it as a set of sets, where a set
> 'name' is given by the value. Thus, for the hash above, we would have
> 3 sets (value1, value2 and value3). Now, i would like to compute the
> intersection of the members of these sets (in this case, the
> intersection would have 1 member, namely key2). One of the problems is
> that i do not have an a priori knowledge of the number of sets to
> compare.

That makes no sense - you can only have one of each key since keys
are unique. If you were to add a key a second time it would replace
the prior value for that key. Hence you would have:

%hash = (


key1 => 'value3',
key2 => 'value3',
key3 => 'value3'
);

instead of what you showed above. Maybe restate your problem in
another manner.

PS: What does it have to do with Tk ?

0 new messages