βBetterβ is a subjective term. However, I would say that code that is easier to understand can be described as "better." For this reason, I came to the conclusion that !keys %hash better, because everyone who wrote the perl code will know what this code does and what it works. !%hash is something, at least I'll have to look to make sure it really works or just looks like it will work. (The reason is that the return value of the hash in the scalar context is rather confusing, while the behavior of arrays in the scalar context is well known and often used.)
In addition !keys %hash preserved.
No, there is no better or safer way to check if the hash is empty.
Benjamin Krupp Apr 14 '17 at 19:14 2017-04-14 19:14
source share