I am trying to figure out h开发者_JAVA技巧ow to delete a hash entry that returns a value of {}
.
I was working with something like this;
if (ref($snapshots{"ID\:$id"}) eq "{}") {
print "ID $id hash no snapshots\n";
}
It does not appear to work. Any ideas?
Given {}
, ref
will be "HASH"
not "{}"
if (ref $snapshots{"ID\:$id"} eq 'HASH' && !scalar keys %{$snapshots{"ID\:$id"}}) {
delete $snapshots{"ID\:$id"};
}
精彩评论