http://qs1969.pair.com?node_id=480747


in reply to Finding Recurring Elements in HoHoA

i would use a different approach and sort the found animals in another hash which is structured in a way, that makes printing easyer
my %animals; for my $state ( keys %bighash ) { for my $zoo ( keys %{ $bighash{$state} } ) { $animals{ $bighash{$state}{$zoo}->[1] }->[0]->{$state}->{$zoo} +++; $animals{ $bighash{$state}{$zoo}->[1] }->[1]++; } } for my $animal ( keys %animals ) { next unless $animals{$animal}->[1] > 1; for my $state ( keys %{ $animals{$animal}->[0] } ) { print "$state\n"; for my $zoo ( keys %{ $animals{$animal}->[0]->{$state} } ) { print "ZOO: $zoo ANIMAL: $animal\n"; } print "\n"; } }

Replies are listed 'Best First'.
Re^2: Finding Recurring Elements in HoHoA
by polettix (Vicar) on Aug 04, 2005 at 10:12 UTC
    Your solution does not take into account that the animal must "1.Occur more than once within the states, AND 2.Occur in more than one states.", it only checks that an animal occurs at least two times in the whole bighash.

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.
      i left that as an excersise to the reader ;-)