#!/usr/bin/perl use strict; use warnings; # initialize a hash my %domains1 = ( com => 'commercial', edu => 'educational', org => 'non-profit' ); # use keys function in scalar context to get the number of keys my $count = keys %domains1; print "number of keys in hash: $count\n"; # use hash in boolean context -- should be TRUE here for not empty if ( %domains1 ) { print "hash is not empty\n"; } else { print "hash is empty\n"; } # zero out the hash %domains1 = (); # use keys function in scalar context to get the number of keys $count = keys %domains1; print "number of keys in hash: $count\n"; # use hash in boolean context -- should be FALSE here for empty if ( %domains1 ) { print "hash is not empty\n"; } else { print "hash is empty\n"; }