我正在尝试检索存储为引用的数组的各个元素。

my @list = ("three 13  3  1  91 3", "one   11  5  1  45 1",
            "two   12  7  1  33 2", "four  14  1  1  26 4");

my @refList = map { [$_, (split)[-1]] } @list;

# see what it is in @refList
use Data::Dumper;
print Dumper(@refList);

print "\n the value is $refList[0][0][1]";

输出
$VAR1 = [
          'three 13  3  1  91 3',
          '3'
        ];
$VAR2 = [
          'one   11  5  1  45 1',
          '1'
        ];
$VAR3 = [
          'two   12  7  1  33 2',
          '2'
        ];
$VAR4 = [
          'four  14  1  1  26 4',
          '4'
        ];

 the value is

但我需要输出
 print "\n the value is $refList[0][0][1]" as 13

如何获得值(value)

最佳答案

my @list = ( "three 13 3 1 91 3", "one 11 5 1 45 1", "two 12 7 1 33 2", "four 14 1 1 26 4" );

my @refList = map { my @t = split; shift(@t); [ $_, @t ]; } @list;

# see what it is in @refList
use Data::Dumper;
print Dumper(@refList);

print "\n the value is $refList[0][0][1]";

关于perl - 如何取消引用数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8501866/

10-11 16:52