I use the following code to check if the hash is empty. Is there a better method and is this safe to use?
if (!keys %hash) { print \"Empty\";}
Simpler:
if (!%hash) {
print "Empty";
}
! imposes a scalar context, and hash evaluated in a scalar context returns:
false if there are zero keys (not defined in the documentation but experimentally returns 0)
A string signifying how many used/allocated buckets are used for >0 keys, which will of course be NOT false (e.g. "3/6")