Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^5: Count non-empty hash values

by Joost (Canon)
on Oct 23, 2005 at 00:36 UTC ( [id://502262]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Count non-empty hash values
in thread Count non-empty hash values

grep length, values %a
is even faster.
ooh nice :-)

I thought of this one:

grep $_, values %a
Which might be even faster (I haven't tested it), but whether it's valid depends on the OP's meaning of "empty"..

Replies are listed 'Best First'.
Re^6: Count non-empty hash values
by ikegami (Patriarch) on Oct 23, 2005 at 03:05 UTC

    That catches undefined values (most likely good) but also catches 0 and "0" (most likely bad). Checking for truth had occured to me, but I decided to be consistent with the other solutions, and "0" counting as empty was too big a question mark. Checking for truth is 22% faster than checking the length, though:

    Rate OP other fishbot Joost ikegami truth OP 193/s -- -32% -67% -88% -89% -91% other 284/s 47% -- -52% -82% -84% -87% fishbot 592/s 207% 109% -- -62% -67% -73% Joost 1578/s 719% 456% 166% -- -13% -29% ikegami 1818/s 843% 540% 207% 15% -- -18% truth 2221/s 1052% 682% 275% 41% 22% --

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 07:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found