Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Count non-empty hash values

by swampyankee (Parson)
on Oct 22, 2005 at 17:44 UTC ( [id://502234]=note: print w/replies, xml ) Need Help??


in reply to Count non-empty hash values

Just to clarify (it's Saturday; I left several IQ points at the office): by empty do you mean the key exists but its value is undefined or do you mean the key exists but its value evaluates to false? My brute force and ignorance approach would be something like this for the first case:
@values = values(%hash); foreach $i (@values) { $count ++ if defined($i); }
or this for the second:
@values = values(%hash); foreach $i (@values) { $count ++ if $i; }
I also found that
$count = (grep { /^$/ } values(%hash))- scalar(values(%hash);
seems to work

emc

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found