I have this code where I want to add 10, 11 and 12 to array arr.
my @num=(0,1,2);
my $i=10;
for my $d (@num){
if (defined($d)) {
my @arr;
$arr[$d] = $i;
$i=$i+1;
my $dvv=dump(\@arr);
print "**** $dvv \n";
}
}
The output is:
**** [10]
**** [undef, 11]
**** [undef, undef, 12]
Why is only the last element of array defined?
use strict and use warnings