Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^5: Count non-empty hash values

by Joost (Canon)
on Oct 23, 2005 at 00:36 UTC ( #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 (Pope) 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?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2020-11-29 20:06 GMT
Find Nodes?
    Voting Booth?

    No recent polls found