如何查看 Berkeley DB (Perl) 中有多少个键?
我只需要找出这个哈希中有多少个元素,我正在查看文档,但唯一可能给我的是 db_stat,并且它下面有一个 TODO。
http://search.cpan.org/dist/BerkeleyDB/BerkeleyDB.pod#Using_db_stat
那么除了创建游标并解析整个内容之外,我怎样才能看到哈希中有多少个键呢?
I simply need to find out how many elements I have in this hash, and I'm looking at the docs but the only thing that might give me this is db_stat, and there's a TODO under it.
http://search.cpan.org/dist/BerkeleyDB/BerkeleyDB.pod#Using_db_stat
So other than creating a cursor and parsing through the entire thing, how can I see how many keys are in the hash?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎在这里找到了答案:
http://download .oracle.com/docs/cd/E17076_02/html/api_reference/C/dbstat.html
命名调用 db_stat 时设置的许多不同变量,包括我正在寻找的“hash_ndata”,它给出了数字键值对。
Seem to have found the answer here:
http://download.oracle.com/docs/cd/E17076_02/html/api_reference/C/dbstat.html
Names many different variables set when db_stat is called, including the one I was looking for, 'hash_ndata', which gives the number of key-value pairs.
您可以将 bdb 数据库绑定到哈希,然后检查哈希中键的数量。在标量上下文中使用时,
keys
函数将为您提供哈希中的键数。不幸的是,我无法测试这个,因为我的系统上没有 dbd。我相信您必须使用包变量来处理
tie
。You can
tie
a bdb database to a hash, then check the number of keys in the hash. Thekeys
function will give you the number of keys in a hash when used in a scalar context.Unfortunately, I can't test this because I don't have dbd on my system. I believe you have to use package variables for handling the
tie
.