in reply to complete deletion from hash

You could use the keys function to test for the existance of any keys.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $h = { 'comp' => { 'cmd' => { 'tc1' => { platform_type => 'all', testsuite_type => 'all', view => 'private' }, 'tc2' => { platform_type => 'all', testsuite_type => 'all', view => 'private'} } } }; delete $h->{comp}{cmd}{tc1}; delete $h->{comp}{cmd}{tc2}; unless (keys %{$h->{comp}{cmd}}){ delete $h->{comp}{cmd}; } unless (keys %{$h->{comp}}){ delete $h->{comp}; } print Dumper($h); __DATA__ ---------- Capture Output ---------- > "c:\perl\bin\perl.exe" _new.pl $VAR1 = {}; > Terminated with exit code 0.

Replies are listed 'Best First'.
Re^2: complete deletion from hash
by inman (Curate) on Nov 24, 2005 at 10:51 UTC
    The following worked in scalar context without using keys to give list context. An empty hash gives 0 in scalar context.
    delete $hoh{Testcase}{comp}{cmd} unless %{$hoh{Testcase}{comp}{cmd}}; delete $hoh{Testcase}{comp} unless %{$hoh{Testcase}{comp}};
Re^2: complete deletion from hash
by rsennat (Beadle) on Nov 24, 2005 at 10:44 UTC
    oh. thats gr8!!!
    thanks a lot