I am using a map to retrieve the first element of a 2D array. Here is a small piece of code.
my $array = [ [1,11,111], [2,22], undef, [4] ];
my @firstList = map { (defined $_) && $_->[0] } @$array;
So, I expect the map to return an array containing elements with either undef or the first element of the $ array element.
but the result is not what I expect. For undef, I get an element of type "scalar".
If I change the map operator with the next block, I get the expected result.
my @firstList = map { $_->[0] } @$array;
Please help me sort out these two statements of the map.
source
share