Perl关于数据结构的查询
我目前使用以下哈希,效果很好
%hash = ( 'env1' => 'server1:port1, server11:port11', 'env2' => 'server2:port2, server22:port22' ) ;
但是,我真正想做的是创建以下数据结构,这将使我更容易提取信息。下面的显然行不通。
( env1 => "server=server1, port=port1", "server=server11, port=port11", env2 => "server=server2, port=port2", "server=server22, port=port22" ) ;
想知道是否有人对创建符合我的要求的数据结构有任何建议。
I currently use the following hash which works fine
%hash = ( 'env1' => 'server1:port1, server11:port11', 'env2' => 'server2:port2, server22:port22' ) ;
However, what I really want to do is create the following data structure, which will make it easier for me to extract the information. The following obviously does not work.
( env1 => "server=server1, port=port1", "server=server11, port=port11", env2 => "server=server2, port=port2", "server=server22, port=port22" ) ;
Wondering if anyone has any suggestions on creating a data structure that would match my requirements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
写这样:
然后像这样访问元素:
这是一个散列,其中值是对匿名数组的引用。
但是当我查看您的数据时,我认为也许有更好的方法来存储它:
然后访问如下元素:
Write this:
And then access elements like this:
This is a hash where the values are references to anonymous arrays.
But when I look at you data I think maybe there is a better way to store it:
And then access elements like this:
鉴于这个问题,很难准确说出您在寻找什么。我怀疑哈希值的哈希值就足够了。您可以这样设置:
要获取值,您可以执行以下操作:
您可以添加其他值,如下所示:
Hard to tell exactly what you're looking for given the question. I suspect a hash of hashes will suffice. You'd set it up like this:
To get the values, you'd do something like this:
You can add additional values like this: