开发者

How can I delete empty hash entires?

开发者 https://www.devze.com 2023-03-07 18:00 出处:网络
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;

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"};
}
0

精彩评论

暂无评论...
验证码 换一张
取 消