Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Count non-empty hash values

by swampyankee (Parson)
on Oct 22, 2005 at 17:44 UTC ( #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
Node Status?
node history
Node Type: note [id://502234]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2020-11-28 23:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?