Perl, an array of dereferencing links

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

#!/usr/bin/perl use strict; use warnings; my @a=([1,2],[3,4]); my @b = @$a[0]; print $b[0]; 

However, it does not work. I expect him to come out 1.

@a - array of links

@b is $a[1] dereferenced (I think)

So what's the problem?

+7
arrays reference perl
source share
1 answer

This stuff is complicated.

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

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

+10
source share

All Articles