#!/usr/bin/perl # Tom Blum # May 2007 # IWA-HWG Homework/ Instructor M. Kowalski #make array of top movies according to AFI @movies = ("Citizen Kane", "Casablanca", "The Godfather", "Gone with the Wind", "Lawrence of Arabia", "The Wizard of Oz", "The Graduate", "On the Waterfront", "Schindler's List", "Singin' in the Rain"); #make sorted and reverse copies of the movie array @sorted_movies = sort @movies; @reversed_movies = reverse @movies; #print out top movies in sorted (alphabetical) order print "\nAccording to AFI the top ten movies of all time\n"; print "are (in alphabetical order):\n\n"; $letter="A"; foreach $movie (@sorted_movies) { print "$letter. $movie\n"; $letter++; } #Use reverse order to quiz user print "\nLet's count them down and see if you can guess their positions.\n"; print "When prompted with the number, enter the letter (A,B, ..., J) of your guess.\n"; print "(Enter L if you need to see the list again.)\n"; $correct_count=0; for($index = 0; $index<10; $index++) { #prompt for user's guess $count = 10-$index; print "\nWhat movie do you think is number $count? "; chomp($response = ); $response = uc $response; #print list if user types "L" ask for new response if($response eq "L") { $letter="A"; foreach $movie (@sorted_movies) { print "$letter. $movie\n"; $letter++; } print "\nWhat movie do you think is number $count? "; chomp($response = ); $response = uc $response; } #see if response is correct $a = $reversed_movies[$index]; $b = $sorted_movies[ord($response) - ord("A")]; if($a eq $b) { print "Yes, $reversed_movies[$index] is correct!\n"; $correct_count++; } else { print "Sorry, no, it was $reversed_movies[$index].\n"; } } #print out original order print "\nAccording to AFI the top ten movies of all time are:\n\n"; foreach $movie (@movies) { print "$movie\n"; } print "\nYou guessed $correct_count correctly\n"; #print out the arrys in the various orders if the user requests it print "\nDo you want a recap? (Enter y for yes): "; chomp($response = ); $response = lc $response; if ($response eq "y") { print "\n\nThe movies in alphabetical order are:\n"; foreach $movie (@sorted_movies) {print "$movie, ";} print "\n\nThe movies from bottom to top are:\n"; foreach $movie (@reversed_movies) {print "$movie, ";} print "\n\nThe movies from top to bottom are:\n"; foreach $movie (@movies) {print "$movie, "}; }