[英]How do I make a Perl “array of arrays of hashes”?
I think what I need is an Array of Array of Hash, but I have no idea how to make that. 我认为我需要的是一个哈希数组数组,但我不知道如何做到这一点。
Can Perl do that? Perl可以做到吗?
And if so, how would the code look like? 如果是这样,代码将如何?
You can address elements of such a data structure thus: 您可以解决此类数据结构的元素:
$x->[1][2]{foo} = "hello"
You don't even have to pre-define the structure. 您甚至不必预先定义结构。 Just start working with the elements as if they're already there. 刚开始使用这些元素就像它们已经存在一样。
perldoc perldsc
是一个很好的文档,可以在Perl中了解数据结构。
my $aah =
[ # outer array
[ # first inner array
{ # first inner hash
foo => 'bar',
},
{ # second inner hash
bar => 'baaz',
},
],
[ # secnd inner array
#...
],
# ...
];
You can access the elements like this: 您可以访问以下元素:
$aah->[0]->[1]->{bar} # => 'baaz'
my $arr =
[
[
{key1 => $value1, key2 => $value2},
{key1 => $value3}
],
[
{rubbish => 'nonsense'},
]
];
etc. 等等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.