You just need to change your logic, so you make a copy when you find something you like, rather than delete everything that you don't like.
replace:
foreach my $k ( keys %{HoH} ) { unless ( $HoH{$k} and values %{$HoH{$k}} ) { delete $HoH{$k}; } }
with :
my %HoHCopy; foreach my $k ( keys %HoH ) { if ( $HoH{$k} and values %{$HoH{$k}} ) { $HoHCopy{$k} = $HoH{$k}; } }
and then replace the calls to %HoH to %HoHCopy below that.
You could also change that same block out with:
my %HoHCopy = map { $_ => $HoH{$k} } grep { $HoH{$_} and values %{$HoH{$_}} } ( keys %HoH ); # or my %HoHCopy = map { ($HoH{$_} and values %{$HoH{$_}}) ? ($_ => $HoH{$k}) : () } ( keys %HoH );
In reply to Re: How not to destroy a Hash in HoH
by jhourcle
in thread How not to destroy a Hash in HoH
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |