in reply to pruning of empty arrayrefs in nested array

Instead of deleting from an array I am using grep. The disadvantage is that this involves some copying (at least twice) so it involves some time and memory.

use strict; use warnings; use Data::Dumper; sub hdb_prune { my $arr = shift; my @res = grep { not ref $_ or hdb_prune( $_ ) } @$arr; return () if not @res; @$arr = @res; return $arr; } my @arr = ( 1, 2, [], 4, [ 11, 22, [], 44, [ 12, []] ] ); hdb_prune( \@arr ); print Dumper \@arr;