Sigh... we already discussed this in the Chatterbox. Read up in perldata:
If you evaluate a hash in scalar context, it returns false if the
hash is empty. If there are any key/value pairs, it returns true;
more precisely, the value returned is a string consisting of the
number of used buckets and the number of allocated buckets, separated
by a slash. This is pretty much useful only to find out whether
Perl's internal hashing algorithm is performing poorly on your data
set. For example, you stick 10,000 things in a hash, but evaluating
%HASH in scalar context reveals "1/16"
, which means only one out
of sixteen buckets has been touched, and presumably contains all
10,000 of your items. This isn't supposed to happen.
Tell me, what part of your question did this not answer? | [reply] [d/l] |
| [reply] |
As bart said, this was already answered in the CB. The obvious counter-question is - exactly why are you doing this?
Perhaps you are confused - perhaps you're looking for a hash reference? Maybe you have an XY Problem?
If bart's answer isn't what you were looking for, then perhaps you've asked the wrong question?
| [reply] |
Are you wondering what 3/8 is? - It's some data about the hash itself, it means perl pre assigned 8 buckets ("memory particles", ooooohhh) to your hash. Of which, 3 are being used. This is kind of useless info, eh? Well, if you have a seriously mammoth hash, like.. loading in a gargantuan buttload of info on say.. a tree slice of a filesystem.. or.. who knows.
If your program runs slow, maybe something you would do is check some mammoth hash, see how many buckets are being used out of those assigned, -- This is usually not needed for you to do unless you are coding some whack stuff. In which case, you'd already know about this bucket thingie. Help any? - It may be what you are looking for is something else.
| [reply] |