Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Finding Recurring Elements in HoHoA

by Taulmarill (Deacon)
on Aug 04, 2005 at 09:45 UTC ( #480747=note: print w/replies, xml ) Need Help??

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.

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

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://480747]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2023-04-01 14:57 GMT
Find Nodes?
    Voting Booth?

    No recent polls found