perl中这个变量的数据结构是什么?
我是 Perl 新手,正在阅读用 Perl 编写的代码。一行内容如下:
$Map{$a}->{$b} = $c{$d};
我熟悉哈希看起来像 %samplehash
并通过 $samplehash{a}="b"
访问,
但是上面的行说明了什么实际上是地图吗?
I am new to perl and reading a code written in perl. A line reads like this:
$Map{$a}->{$b} = $c{$d};
I am familiar with hash looking like %samplehash
and accessed as $samplehash{a}="b"
but what does the above line say about what is Map actually?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
给定这些变量:
赋值
结果看起来像这样的哈希:
%Map
是一个哈希,在赋值之后通过自动激活包含哈希引用: 如果尚不存在,则自动创建内部哈希引用通过 Perl 通过访问%Map
哈希中的元素$Map{$a}->{$b}
来实现。Given these variables:
The assignment
Results in a hash looking like this:
%Map
is a hash, which after the assignment contains a hash ref through autovivification: If not already there, the inner hash ref is automatically created by Perl by accessing the element$Map{$a}->{$b}
in the%Map
hash.相当于
只
使用哈希引用
$Map{$a}
而不是%hash
。请参阅 http://perlmonks.org/?node=References+quick+reference关于如何使用嵌套数据结构的一些容易记住的规则。
此外,在自动激活(默认情况下)的情况下,如果
$Map{$a}
以不存在或 undef 的形式启动,它将被隐式初始化为新的哈希引用。is equivalent to
which is like
only using the hash reference
$Map{$a}
instead of%hash
.See http://perlmonks.org/?node=References+quick+reference for some easy to remember rules about how to use nested data structures.
Additionally, with autovivification on (which it is by default), if
$Map{$a}
starts as not existing or undef, it will be implicitly initialized to be a new hash reference.$Map 中键 $a 的值是关联数组的引用,该数组的键名称存储在 $b 中。
%Map = ( $a => { $b => $c{$d} }, ...)
the value for key $a in $Map is an reference of associate array which has a key name stored in $b.
%Map = ( $a => { $b => $c{$d} }, ...)