msk_0984 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Assigning a hash variable to a scalar variable
by bart (Canon) on May 22, 2006 at 09:15 UTC
    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?

      As someone said, "the value of a hash in scalar context is of no use to a Perl programmer, only to a perl programmer". (Or something like that!)

Re: Assigning a hash variable to a scalar variable
by McDarren (Abbot) on May 22, 2006 at 09:21 UTC
    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?

Re: Assigning a hash variable to a scalar variable
by leocharre (Priest) on May 22, 2006 at 19:30 UTC

    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.