如何在 Perl 中创建哈希的哈希?
我是 Perl 新手。我需要在 Perl 中定义一个如下所示的数据结构:
city 1 -> street 1 - [ name , no of house , senior people ]
street 2 - [ name , no of house , senior people ]
city 2 -> street 1 - [ name , no of house , senior people ]
street 2 - [ name , no of house , senior people ]
我怎样才能实现这个?
I am new to Perl. I need to define a data structure in Perl that looks like this:
city 1 -> street 1 - [ name , no of house , senior people ]
street 2 - [ name , no of house , senior people ]
city 2 -> street 1 - [ name , no of house , senior people ]
street 2 - [ name , no of house , senior people ]
How can I acheive this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是使用哈希引用的另一个示例:
然后您可以通过以下方式访问数据:
或者:
Here is an another example using a hash reference:
You then can access the data the following way:
Or:
答案
我找到了可以用这种方式生成的
I found the answer like
i can generate in this way
Perl 数据结构手册 perldsc 可能会有所帮助。它有示例向您展示如何创建通用数据结构。
The Perl Data Structures Cookbook, perldsc, may be able to help. It has examples showing you how to create common data structures.
如果你想推
(0r)
If you want to push
(0r)
您可以在这个答案中阅读我的简短教程。简而言之,您可以将对哈希的引用放入值中。
You may read my short tutorial at this answer. In short you may put reference to hash into the value.