Perl:关于哈希图的基本问题

发布于 2024-10-03 17:01:36 字数 134 浏览 0 评论 0原文

$hash_map{$key}->{$value1} = 1;

我只是 perl 的初学者,我需要这个表达式的帮助,这个表达式是什么意思?我假设将创建一个新的键/值对,但是这里的 1 是什么意思?

$hash_map{$key}->{$value1} = 1;

I'm just a beginner at perl and I need help in this expression, what does this expression mean? I assume that a new key/value pair will be created but what is the meaning of 1 here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

抱猫软卧 2024-10-10 17:01:37

这里你得到的是散列的散列,或者是两级散列。 $hash_map{$key} 保存一个哈希引用,它指向另一个哈希。 $hash_map{$key}{$value}(在这种情况下可以省略箭头)是第二个哈希中的特定键。 1 是分配给该哈希键的值。

有关此主题的更多信息,请参阅 Perl 数据结构手册 有关哈希值的部分哈希,另请参阅 Perl 参考教程 了解引用的工作原理。

What you've got here is a hash of hashes, or a two-level hash. $hash_map{$key} holds a hash reference, which points to another hash. $hash_map{$key}{$value} (the arrow can be omitted in this case) is a particular key in the second hash. The 1 is the value being assigned to that hash key.

For more on this topic, see Perl Data Structures Cookbook section on Hashes of Hashes, and also see the Perl reference tutorial for how references work.

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