Perl, dereference array of references

后端 未结 1 1605
慢半拍i
慢半拍i 2021-02-08 23:03

In the following Perl code, I would expect to be referencing an array reference inside an array

#!/usr/bin/perl

use strict;
use warnings;

my @a=([1,2],[3,4]);
         


        
1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-09 00:03

    This stuff is tricky.

    @$a[0] is parsed as (@$a)[0], dereferencing the (undefined) scalar $a

    You wanted to say @{$a[0]}.

    0 讨论(0)
提交回复
热议问题