Mega Code Archive

 
Categories / Perl / Hash
 

Delete from hash

#!C:/Perl/Bin %animals = (H=> 'h', S=> 's', G=> 'g'); print "$animals{'S'} \n\n"; foreach $creature(keys %animals) {      print "$creature \n"; } print "\n\ndeleting...\n\n"; delete($animals{Shark}); foreach $creature(keys %animals) {      print "$creature \n"; } print "\n\n'emptying' the hash ...\n\n"; %animals=(); print "Displaying empty hash ...\n\n"; foreach $creature(keys %animals) {      print "$creature \n"; }