#!/usr/bin/perl -w ####################################################### # class3_05_hash_functs2 # # try out another of Perl's hash functions: exists, delete # # modified by Sharon Tuttle from "Learning Perl", # by Schwartz and Phoenix # # last modified: 4-13-03 ####################################################### %order_totals = ("chocolate"=>13, "hamburger"=>10, "tofu dog"=>12, "fried chicken"=>0, "pizza"=>0, ); # ask user to enter a food for which they'd like to see a total print "for what food do you want to see a total? \n"; chomp($food = ); if (exists $order_totals{$food} ) { print "there have been $order_totals{$food} order(s) for $food\n"; } else { print "sorry, $food is not one of our menu items.\n"; } # ask user to enter a food to delete from the hash print "\nenter a food to be deleted:\n"; chomp($food_to_delete = ); delete $order_totals{$food_to_delete}; print "\nHere are remaining foods and their totals:\n"; foreach $food (sort keys %order_totals) { print "$food => $order_totals{$food}\n"; } # end of class3_05_hash_functs2