在我看来,其中一些应该失败,但他们都输出了他们应该:
$, = "\n";
%test = (
    "one" => ["one_0", "one_1"],
    "two" => ["two_0", "two_1"]
);
print @{$test{"one"}}[0],
      @{$test{"one"}}->[0],
      $test{"two"}->[0],
      $test{"one"}[1];
为什么是这样?
你的第一个例子与其他例子不同.这是一个数组切片 - 但是伪装,因为你只需要一个项目.
@{$test{"one"}}[0];
@{$test{"one"}}[1, 0];  # Another slice example.
您的其他示例是在多级数据结构中取消引用项目的替代方法.但是,不推荐使用数组进行取消引用(请参阅perldiag).
@{$test{"one"}}->[0]; # Deprecated. Turn on 'use warnings'.
$test{"two"}->[0];    # Valid.
$test{"one"}[1];      # Valid but easier to type.
关于最后一个例子,两个彼此相邻的下标->在它们之间有隐含.例如,参见perlreftut 中对箭头规则的讨论.
| 归档时间: | 
 | 
| 查看次数: | 90 次 | 
| 最近记录: |