如何查看 Berkeley DB (Perl) 中有多少个键?

发布于 2024-10-04 23:47:00 字数 284 浏览 7 评论 0原文

我只需要找出这个哈希中有多少个元素,我正在查看文档,但唯一可能给我的是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮色兮凉城 2024-10-11 23:47:01

似乎在这里找到了答案:

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.

不顾 2024-10-11 23:47:01

您可以将 bdb 数据库绑定到哈希,然后检查哈希中键的数量。在标量上下文中使用时,keys 函数将为您提供哈希中的键数。

use DB_File;
our %dbHash;

yadda, yadda, yadda;
tie (%dbHash, "DB_File", $dbFileName);
print "The number of keys in $dbFileName is " . keys(%dbHash) . "\n";

不幸的是,我无法测试这个,因为我的系统上没有 dbd。我相信您必须使用包变量来处理tie

You can tie a bdb database to a hash, then check the number of keys in the hash. The keys function will give you the number of keys in a hash when used in a scalar context.

use DB_File;
our %dbHash;

yadda, yadda, yadda;
tie (%dbHash, "DB_File", $dbFileName);
print "The number of keys in $dbFileName is " . keys(%dbHash) . "\n";

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文