in reply to pruning of empty arrayrefs in nested array
sub prune_with_map { my $aref = shift; @{ $aref } = map { if( ref( $_ ) ) { if( @{ $_ } ) { prune_with_map( $_ ); } else { (); } } else { $_; } } @{ $aref }; return ( $aref ); } sub prune_with_foreach { my $aref = shift; my $count = 0; foreach ( @$aref ) { if( ref( $_ ) ) { if( @{ $_ } ) { prune_with_foreach( $_ ); } else { delete $aref->[ $count ]; } } else { $_; } $count++; } return ( $aref ); }
|
|---|