gpt4 book ai didi

perl - 哈希值中的 4/16 是什么?

转载 作者:行者123 更新时间:2023-12-02 19:28:06 24 4
gpt4 key购买 nike

if (%hash){
print "That was a true value!\n";
}

That will be true if (and only if) the hash has at least one key-value pair.

The actual result is an internal debugging string useful to the people who maintain Perl. It looks something like "4/16," but the value is guaranteed to be true when the hash is nonempty, and false when it's empty. --Llama book

4/16 是什么?谁能告诉我一个小程序,从中我可以看到结果是 4/16?

最佳答案

来自perldoc 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.

因此,4/16 将是已使用/已分配的存储桶计数,类似以下内容将显示此值:

%hash = (1, 2);
print scalar(%hash); #prints 1/8 here

关于perl - 哈希值中的 4/16 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6723172/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com