in reply to How to test for empty hash?
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to test for empty hash?
by ikegami (Patriarch) on Aug 06, 2021 at 09:34 UTC | |
by Anonymous Monk on Aug 06, 2021 at 11:01 UTC | |
Re^2: How to test for empty hash?
by LanX (Saint) on Aug 06, 2021 at 09:16 UTC | |
by haukex (Archbishop) on Aug 06, 2021 at 11:14 UTC | |
by LanX (Saint) on Aug 06, 2021 at 12:37 UTC |