in reply to Find number of unique values in hash
Here are two ways to do it.
use warnings; use strict; my %hoh = ( kevin => { age => "12", favorite_color => "blue", gender => "boy", }, john => { age => "11", favorite_color => "green", gender => "boy", }, lisa => { age => "11", favorite_color => "pink", gender => "girl", }, sara => { age => "13", favorite_color => "purple", gender => "girl", }, shelly => { age => "12", favorite_color => "purple", gender => "girl", }, ); my $num_12 = grep { $_ == 12 } map { $hoh{$_}->{'age'} } keys %hoh; my $num_alt = grep { $hoh{$_}->{'age'} == 12 } keys %hoh; print "Num 12: $num_12\n"; print "Num 12 alt: $num_alt\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Find number of unique values in hash
by CountZero (Bishop) on Jan 19, 2010 at 22:16 UTC | |
by saberworks (Curate) on Jan 19, 2010 at 22:21 UTC |
In Section
Seekers of Perl Wisdom