我如何访问内在属性?
我有一个像这样的 perl 变量。 我如何访问内置属性(如“706”)?
my @config = [
{
'x' => [ 565, 706 ],
'y' => [ 122 ],
'z' => 34,
'za' => 59,
}
];
编辑: print Dumper($config[0]);
产量:< code>$VAR1 = undef;
看起来我使用 $config[0][0]->{x}[1];
获得访问权限。为什么我必须使用 [0][0] (一个很清楚,但他第二个......)?
EDIT2:我很抱歉更改了数据结构,但是给我的定义发生了变化。
I have a perl variable like this. How can i access the inlying properties (like '706')?
my @config = [
{
'x' => [ 565, 706 ],
'y' => [ 122 ],
'z' => 34,
'za' => 59,
}
];
EDIT: print Dumper($config[0]);
yields : $VAR1 = undef;
Looks like i get acces using $config[0][0]->{x}[1];
. Why do i have to use [0][0] (one is clear, but he ssecond...)?
EDIT2: I am sorry for changing the data structure, but the definition which was given to me changed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的变量相当于:
因此,如果您想获得 706,您可以执行以下操作:
根据问题中的新数据更新
有了更新的问题,您现在可以通过以下方式访问:
新更新根据新的数据结构
根据您提供的最后更新的数据结构:
您分配一个匿名数组[...],它本身包含一个哈希{...}
到数组@config,这将填充@config的第一个元素
对于匿名数组,
我认为您想要执行以下任一操作:
Your variable is equivalent to :
So if you want to get the 706, you can do:
Updated according to new data in the question
With the updated question, you can access now by :
New update according to new data structure
According to the last updated data structure you provide:
you assign an anonymous array [...] that contains itself a hash {...}
to an array @config, this will populate the first element of @config
with the anonymous array
I think you want to do either:
[编辑: 遵循转移问题定义。]
给出:
那么这就可以了:
当然理解这只是语法糖:
并且这只是语法糖for:
反过来又只是语法糖 for:
又是语法糖 for:
当然,它等价于:
[EDIT: Follow the shifting problem definition.]
Given:
Then this will do it:
understanding of course that that is merely syntactic sugar for:
and that that is just syntactic sugar for:
which in turn is just syntactic sugar for:
which again is syntactic sugar for:
and that, of course, is equivalent to: