Commit 6cbdc45e authored by Clément OUDOT's avatar Clément OUDOT
Browse files

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

parent 2bbabb66
......@@ -137,17 +137,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";
......
Supports Markdown
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