【问题标题】:perl hash ref operator is working weirdlyperl hash ref 运算符工作异常
【发布时间】:2014-07-05 20:00:27
【问题描述】:

我有一个由哈希引用列表组成的数组引用。

代码如下:

use strict;
use warnings;

my $arrayRef = [
    {
        'URL' => 'http://example.com/1.jpg',
        'ORD' => '1',
    },
    {
        'URL' => 'http://example.com/2.jpg',
        'ORD' => '2',
    },
    {
        'URL' => 'http://example.com/3.jpg',
        'ORD' => '3',
    },
];

print $arrayRef->[0]->{URL},"\n";     # http://example.com/1.jpg
print $arrayRef->[0]{URL},"\n";       # http://example.com/1.jpg

由于它是一个哈希引用,我使用-> 运算符来获取一个值,但我在不使用-> 运算符的情况下得到相同的值,可以吗?

【问题讨论】:

  • perl hash ref 运算符工作奇怪方便

标签: perl hash


【解决方案1】:

它是有效的,一种语法糖,它指的是同一个项目。 Perl references tutorial 写了这篇文章

【讨论】:

    猜你喜欢
    • 2014-11-09
    • 2020-06-30
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 2015-11-27
    • 2015-04-25
    • 1970-01-01
    • 2013-07-29
    相关资源
    最近更新 更多