The node Truth and Falsehood also briefly discusses this. In short, a hash in boolean context returns a false value when it is empty, so if (!%hash) will portably detect an empty hash. To portably get the number of keys in a hash, use keys in scalar context; scalar(%hash) is not backwards compatible for counting keys (as the documentation quoted by LanX explains).
Minor edits clarification.
In reply to Re: How to test for empty hash?
by haukex
in thread How to test for empty hash?
by scareduck
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |