in reply to Re^2: How to extract a row or column of two-dimensional hash
in thread How to extract a row or column of two-dimensional hash
Updated: $HoH{$group} is a reference to a hash. I refactored your code as follows:
#!/usr/bin/env perl use warnings; use strict; my %HoH = ( flintstones => { lead => "fred", pal => "barney", }, jetsons => { lead => "george", wife => "jane", kid => "jane", }, simpsons => { lead => "homer", wife => "marge", kid => "bart", }, ); my $total_jane_count = 0; for my $group ("simpsons" ,"jetsons" ) { my %family_hash = %{ $HoH{$group} }; for my $name (values %family_hash) { if ($name eq 'jane') { $total_jane_count++ } } } print "total_jane_count = $total_jane_count\n";
This prints:
total_jane_count = 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to extract a row or column of two-dimensional hash
by PerlKitten (Novice) on Jan 15, 2008 at 03:51 UTC |