in reply to how can i return the common keys from a hash
This is a typical intersection problem. Yes, a FAQ. Go read perlfaq4. You basically create some arrays with the hash keys and perform the intersection over them.
Update: Hmm, seems I misread "values". Well, you can perform the intersection of the values as it's explained in the FAQ. For obtaining the corresponding keys, you can reverse the hash:
my %c = ( a=>1, b=>2, c=>3 ); my %rev_c = reverse %c; use Data::Dumper;print Dumper \%rev_c; __END__ $VAR1 = { '1' => 'a', '3' => 'c', '2' => 'b' };
Of course, you're going to have problems if there's more than one key with the same value, since the action of reversing the hash will eliminate all of those keys but one.
--
David Serrano
|
|---|