⭐ in reply to How to check whether a hash is empty (has no keys)?
Just use the name of the hash in scalar context, such as
if (%foo) { # %foo has at least one key } else { # %foo has no keys }
If you want to be very explicit, you can also write
orif (!!%foo) { ... }
orif (scalar %foo) { ... }
if (0+%foo) { ... }
|
|---|