albert has asked for the wisdom of the Perl Monks concerning the following question:
There are a couple of different ways I'd like to count the keys on this hash.%hash = ( 'a' => { 'x' => 40, 'z' => 102 }, 'b' => { 'z' => 100, 'x' => 10, 'y' => 20 }, 'c' => { 'x' => 50 }, 'd' => { 'z' => 101, 'y' => 30 } );
1. How can I count the number of keys where 'x' has a defined value, but does not have a value for 'y'?
2. How can I count the number of keys which have a defined value for 'z'?
Thanks for all shared wisdom.
Update:
Thanks for showing me how to do this.
One additional thing I forgot to ask in my original question.
How would I also count the number of keys with a value of 101 for 'z'?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Counting hash of hashes elements
by edan (Curate) on Nov 01, 2004 at 11:25 UTC | |
|
Re: Counting hash of hashes elements
by Aragorn (Curate) on Nov 01, 2004 at 11:25 UTC | |
|
Re: Counting hash of hashes elements
by perlcapt (Pilgrim) on Nov 01, 2004 at 11:53 UTC | |
|
Re: Counting hash of hashes elements
by NetWallah (Canon) on Nov 01, 2004 at 17:07 UTC | |
by perlcapt (Pilgrim) on Nov 02, 2004 at 00:56 UTC | |
|
Re: Counting hash of hashes elements
by TedPride (Priest) on Nov 01, 2004 at 20:59 UTC |