I have the following code which defines a nested array and then loops through the array and outputs it. I would like to use the commented out line to extract the inner arrays but it doesn't work because it flattens out the inner arrays. I instead have to use the subsequent three lines. How can I get the commented out line to work properly?
use Data::Dumper;
my @arr1;
for $i (0..9)
{
my @arr2;
my @arr3;
for $j ('A'..'D') {
push @arr2, $j;
push @arr3, int(rand(100));
}
push @arr1, [$i, \@arr2, \@arr3];
}
for $linkarray (@arr1) {
#my ($i, @arr2, @arr3) = @$linkarray;
my $i = @$linkarray[0];
my @arr2 = @$linkarray[1];
my @arr3 = @$linkarray[2];
print "i: $i\narr2: " . Dumper(@arr2) . "\narr3: " . Dumper(@arr3) . "\n";
}
my ($i, $arr2_ref, $arr3_ref) = @$linkarray;my @arr2 = @$arr2_ref;or you can just use them directly:my $first = $arr2_ref->[0];