Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Counting hash of hashes elements

by Aragorn (Curate)
on Nov 01, 2004 at 11:25 UTC ( [id://404273]=note: print w/replies, xml ) Need Help??


in reply to Counting hash of hashes elements

Here's a way:
#!/usr/local/bin/perl use strict; use warnings; my %hash = ( 'a' => { 'x' => 40, 'z' => 102 }, 'b' => { 'z' => 100, 'x' => 10, 'y' => 20 }, 'c' => { 'x' => 50 }, 'd' => { 'z' => 101, 'y' => 30 } ); my $x_but_not_y = 0; my $z = 0; foreach my $key (keys %hash) { $x_but_not_y++ if defined $hash{$key}->{x} and not defined $hash{$ +key}->{y}; $z++ if defined $hash{$key}->{z}; } print "number of keys where x defined, but not y: $x_but_not_y\n"; print "number of keys where z defined: $z\n";
Arjen

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-19 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found