#!/usr/bin/perl use strict; use warnings; my %HoH = ( elt1 => { A => "ccc", B => "ccc", C => "ccc", }, elt2 => { A => "ccc", C => "ccc", D => "ccc", B => "ccc", }, elt3 => { A => "ccc", E => "ccc", C => "ccc", }, ); my %count; my $count = keys %HoH; while (my ($name, $hash) = each %HoH) { while (my ($key) = each %$hash) { $count{$key}++; } } while (my ($name, $hash) = each %HoH) { while (my ($key) = each %$hash) { delete $$hash{$key} unless $count{$key} == $count; } } use Data::Dumper; print Dumper \%HoH; __END__ $VAR1 = { 'elt2' => { 'A' => 'ccc', 'C' => 'ccc' }, 'elt3' => { 'A' => 'ccc', 'C' => 'ccc' }, 'elt1' => { 'A' => 'ccc', 'C' => 'ccc' } };
In reply to Re: Common elements of a hash of hashes
by Perl Mouse
in thread Common elements of a hash of hashes
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |