The likely cause of your problems is that (despite the name) delete on an array element doesn't completely remove that element from the array, it only sets it to be undef.
The simplest way to completely remove unwanted from elements from an array is to use grep: @array = grep{ <test for wanted> } @array;
But as you want to do it recursively, something like this might work for your problem (untested!):
sub prune { my $aref = shift; @{ $aref } = map { if( ref() eq 'ARRAY' ) { ## an arrayref? if( @{ $_ ) { ## Has values, recurse and return the prune +d ref (or nothing if it was empty after pruning). prune( $_ ); } else { ## return nothing (); } } else { ## not an array ref, return it whatever it is $_; } } @{ $aref }; return @{ $aref } ? $aref : (); ## Still contains something, retur +n it; or nothing. } my $refWanted = prune( \@nested );
In reply to Re: pruning of empty arrayrefs in nested array
by BrowserUk
in thread pruning of empty arrayrefs in nested array
by building_arch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |