list of hashes

Hello everyone,

I was wondering if someone can help me with this problem:

@LoHashes = ({"a"=>1,"b"=>2,"c"=>3,"d"=>4},
                    {"a"=>5,"b"=>6,"c"=>7});

@LoHashes = create_list(\&LoHashes);
sub create_list
{
   foreach $hash(@LoHashes)
    {
       foreach (sort keys %$hash)
        {
           print "$_ $hash{$_} ";
        }
    }
}

This code will list the hashes inside @LoHashes. However, I want to list a, b, and c key/value pairs only (repeated pairs), not d. Does anyone have any suggestion??

Thanks a lot and happy Thanksgiving,

new bie

Read the comment lines

@LoHashes = ({"a"=>1,"b"=>2,"c"=>3,"d"=>4},
      {"a"=>5,"b"=>6,"c"=>7});
 
@LoHashes = create_list(\&LoHashes);
sub create_list
{
 foreach $hash(@LoHashes)
 {
  foreach (sort keys %$hash)
  {
   ### temp hash used to increment the key value.
   ### if the value is greater than 2 assign to
   ### the result hash for appropriate keys to corresponding value
   if ( ++$temp{$_} >= 2) {
    $result{$_} = $$hash{$_};
   }
  }
 }
}
### Finally you got the updated values for that corresponding keys.
print "\n$_ : $result{$_}" for (sort keys %result);

Thanks for replying k_manimuthu, I've tried the script you suggested and it worked fine. However, it only print out the newest key/value pairs of repeated pairs. I'd like to print all key/value pairs of repeated pairs. And sorry, I wasn't clear in original post.

I'll try to work on your code and see if I can get it the way I need. If you have any suggestion, please help me out.

thanks a lot,

new bie,