The suggestion to use if (%bar){}here should probably be replaced with if (keys %bar){}, as using a hash directly for this purpose is several orders of magnitude slower in some instances. Perl seems to be optimized to deal with the specific case of if (%hash){}, but the performance drops dramatically for, say, using unless, which isn't present with the keys %hash variant:
The suggestion to use
if (%bar){}
here should probably be replaced withif (keys %bar){}
, as using a hash directly for this purpose is several orders of magnitude slower in some instances. Perl seems to be optimized to deal with the specific case ofif (%hash){}
, but the performance drops dramatically for, say, usingunless
, which isn't present with thekeys %hash
variant: