【问题标题】:what does -> implies in here in this perl code? [duplicate]在这个 perl 代码中 -> 意味着什么? [复制]
【发布时间】:2018-12-27 22:59:37
【问题描述】:
open PROPS, $propertyFile or die "Cannot open $propertyFile";
while ( my $lines = <PROPS> ) {
    chop $line;
    my @fields = split(/,/, $line)
    $r_CntrProp->{$fields[0]}->{$fields[1]} = {
        'behaviour'  => $fields[2],
        'type'       => $fields[3],
        'compressed' => $fields[4]
    };
}

propertyFile 正在被用户作为输入文件读取。

【问题讨论】:

标签: perl hashmap


【解决方案1】:

$r_CntrProp-&gt;{$fields[0]}-&gt;{$fields[1]}

在这段代码中,对于每个箭头 (-&gt;):

  • 左边是哈希引用
  • 右侧,包含在{} 之间,是一个哈希键

表达式允许访问存储在哈希引用中的键下的任何内容。您的代码实际上为该哈希条目分配了一些东西(哈希引用)。

请参阅 The Arrow Operator in perlopUsing References in perlref

基本上,$r_CntrProp对哈希引用的哈希的引用,例如:

my $r_CntrProp  = {
    foo => {
        bar => 'baz'
    }
};

print $r_CntrProp->{foo}->{bar}, "\n";

产量:

baz

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-31
    • 2014-03-23
    相关资源
    最近更新 更多