note
Aragorn
First of all, the notation <code>%hash = { ... </code> is wrong. You either assign a hash with <code>%hash = ( ... </code> or a hash <em>reference</em> with <code>$hash = { ... </code>. Watch those parentheses and curly braces. See [perldoc://perlreftut] and [perldoc://perlref] for more information.
<p>
As for deleting:
<code>
#!/usr/bin/perl
use Data::Dumper;
$hash = {
abc => {
'def' => 1,
},
ghi => {
jkl => 1,
mno => 1,
},
};
print Dumper(\$hash);
delete($hash->{abc}->{def});
print Dumper(\$hash);
__END__
$VAR1 = \{
'abc' => {
'def' => 1
},
'ghi' => {
'mno' => 1,
'jkl' => 1
}
};
$VAR1 = \{
'abc' => {},
'ghi' => {
'mno' => 1,
'jkl' => 1
}
};
</code>
The second question: I don't know :-). Having an undefined hash value is perfectly valid, so the upper level is not automatically deleted when the lower level becomes undefined. You could add a statement like <code>delete $hash->{$key} if not keys %{$hash->{$key}}</code>. This deletes the key only if the hash it references is empty.
<p>
Arjen
315063
315063