#!/usr/bin/perl -w # assignment #2 solution #---------------------------------------------------- # Create a single array containing the names of four of your favorite foods # and a second array with four of your least liked foods. @yum = qw(pizza burritos twinkies calzones); @vomit = ('liver', 'quiche', 'eggs', 'circus peanuts'); # Add another element to the end of each array by asking the user for another # food the like/hate. # Print out the last two items in the least liked foods array. Include some # descriptive text to clarify your output. print "What is another food you like?\n"; chomp($goodfood = <STDIN>); push(@yum, $goodfood); print "The last two values of the foods I like are: @yum[$#yum - 1,$#yum]\n\n"; print "What is another food you hate?\n"; chomp($badfood = <STDIN>); push(@vomit, $badfood); print "The last two values of the foods I hate are: @vomit[$#vomit - 1,$#vomit]\n\n"; #For the "favorite foods" array, move the value of the first element of the # array to become the last element of the same array. push(@yum, shift(@yum)); # Print out the first and last elements of both arrays to show the changes from # the previous step along with some descriptive text. print "First and last values of the foods I hate are: @vomit[0,$#vomit]\n\n"; print "First and last values of the foods I like are: @yum[0,$#yum]\n\n"; # Remove the last element of the favorite foods array and add it to the # beginning of the disliked foods array unshift(@vomit, pop(@yum)); # Print out the first and last elements of both arrays to show the changes from # the previous step along with some descriptive text. print "First and last values of the foods I hate are: @vomit[0,$#vomit]\n\n"; print "First and last values of the foods I like are: @yum[0,$#yum]\n\n"; # Remove the last element of the disliked foods array and display it to the # terminal with some descriptive text. $removed = pop(@vomit); print "We removed $removed from the list of foods I hate.\n"; # Print to the terminal the number of elements in each array with some text. $vomit_count = scalar(@vomit); $yum_count = scalar(@yum); print "There are $vomit_count foods I hate and $yum_count foods I like.\n"; # Delete both arrays before exiting the program. undef @yum; undef @vomit; exit;