I've the below Input and the expected output.
Input : [undef,[0,1],2]
Expected Output : [0,1,2]
Code I've written:
use Data::Dumper;
my $input=[undef,[0,1],2];
my @arr=@{$input};
@arr = grep {defined} @arr;
my @arrnew;
foreach my $value (@arr){
if (ref $value eq 'ARRAY') {
push @arrnew,@{$value};
} else {
push @arrnew,$value;
}
}
print Dumper(@arrnew);
Question: Although, this gives me the correct output, would like to know if any simpler way of doing this in perl.