Commit 66313e48 authored by Clément OUDOT's avatar Clément OUDOT

Check if keys exist before deleting it in the HASH (#1520)

parent 25ca7993
......@@ -140,17 +140,44 @@ sub delKey {
foreach my $el (@list) {
my @path = split $sep, $el->[0];
if ( $#path == 0 ) {
delete $new->{ $path[0] }->{ $el->[1] };
if ( exists $new->{ $path[0] }
&& exists $new->{ $path[0] }->{ $el->[1] } )
{
delete $new->{ $path[0] }->{ $el->[1] }
if exists $new->{ $path[0] }->{ $el->[1] };
}
}
elsif ( $#path == 1 ) {
delete $new->{ $path[0] }->{ $path[1] }->{ $el->[1] };
if ( exists $new->{ $path[0] }
&& exists $new->{ $path[0] }->{ $path[1] }
&& exists $new->{ $path[0] }->{ $path[1] }->{ $el->[1] } )
{
delete $new->{ $path[0] }->{ $path[1] }->{ $el->[1] };
}
}
elsif ( $#path == 2 ) {
delete $new->{ $path[0] }->{ $path[1] }->{ $path[2] }->{ $el->[1] };
if ( exists $new->{ $path[0] }
&& exists $new->{ $path[0] }->{ $path[1] }
&& exists $new->{ $path[0] }->{ $path[1] }->{ $path[2] }
&& exists $new->{ $path[0] }->{ $path[1] }->{ $path[2] }
->{ $el->[1] } )
{
delete $new->{ $path[0] }->{ $path[1] }->{ $path[2] }
->{ $el->[1] };
}
}
elsif ( $#path == 3 ) {
delete $new->{ $path[0] }->{ $path[1] }->{ $path[2] }->{ $path[3] }
->{ $el->[1] };
if ( exists $new->{ $path[0] }
&& exists $new->{ $path[0] }->{ $path[1] }
&& exists $new->{ $path[0] }->{ $path[1] }->{ $path[2] }
&& exists $new->{ $path[0] }->{ $path[1] }->{ $path[2] }
->{ $path[3] }
&& exists $new->{ $path[0] }->{ $path[1] }->{ $path[2] }
->{ $path[3] }->{ $el->[1] } )
{
delete $new->{ $path[0] }->{ $path[1] }->{ $path[2] }
->{ $path[3] }->{ $el->[1] };
}
}
else {
die $el->[0] . " has too many levels. Aborting";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment