您的变量相当于:
my $config = [
'x', [ 565, 706 ],
'y', [ 122 ],
'z', 34,
'za', 59,
];
所以如果你想得到706,你可以这样做:
print $config->[1][1];
根据问题中的新数据更新
有了更新的问题,您现在可以通过以下方式访问:
say $config->[0]{x}[1];
根据新数据结构进行新更新
根据您提供的最后更新的数据结构:
my @config = [
{
'x' => [ 565, 706 ],
'y' => [ 122 ],
'z' => 34,
'za' => 59,
}
];
您将一个包含自身哈希 {...} 的匿名数组 [...] 分配给数组 @config,这将使用匿名数组填充 @config 的第一个元素
say Dumper \@config;
$VAR1 = [
[
{
'y' => [
122
],
'za' => 59,
'x' => [
565,
706
],
'z' => 34
}
]
];
say $config[0][0]{x}[1]; #prints 706
我想你想做的任何一个:
my $config = [
{
'x' => [ 565, 706 ],
'y' => [ 122 ],
'z' => 34,
'za' => 59,
}
];
say $config->[0]{x}[1]; #prints 706
my @config = (
{
'x' => [ 565, 706 ],
'y' => [ 122 ],
'z' => 34,
'za' => 59,
}
);
say $config[0]{x}[1]; #prints 706