How to delete an empty hash?

I am trying to figure out how to remove a hash entry that returns a value {}.

I worked with something like this:

if (ref($snapshots{"ID\:$id"}) eq "{}") {
    print "ID $id hash no snapshots\n";
}

He does not work. Any ideas?

+5
source share
1 answer

Taking into account {}, refwill "HASH"not"{}"

if (ref $snapshots{"ID\:$id"} eq 'HASH' && !scalar keys %{$snapshots{"ID\:$id"}}) {
    delete $snapshots{"ID\:$id"};
}
+7
source

All Articles