#!/usr/bin/perl # # Name : Matthew Reeves # # Program for voting for the 84th Academy Awards # #use diagnostics; use warnings; use strict; use feature ":5.10"; #declare, and initialize (as appropriate) variables and arrays my $count = 0; my $tmp = 0; my $choice = 0; my @selection; #create an array storing category names my @array = ('Best Picture', 'Actress In A Leading Role', 'Actor In A Supporting Role', 'Costume Design', 'Directing', 'Makeup', 'Music (Original Score)', 'Music (Original Song)'); #create a 2 dimensional array for nominees my @matrix = (['The Artist', 'The Descendants', 'Extremely Loud & Incredibly Close', 'The Help', 'Hugo', 'Midnight in Paris', 'Moneyball', 'The Tree of Life', 'War Horse'], ['Glenn Close, Albert Nobbs', 'Viola Davis, The Help', 'Rooney Mara, The Girl with the Dragon Tattoo', 'Meryl Streep, The Iron Lady', 'Michelle Williams, My Week With Marilyn'], ['Kenneth Branagh, My Week With Marilyn', 'Jonah Hill, Moneyball', 'Nick Nolte, Warrior', 'Christopher Plummer, Beginners', 'Max von Sydow, Extremely Loud & Incredibly Close'], ['Anonymous', 'The Artist', 'Hugo', 'Jane Eyre', 'W.E.'], ['The Artist, Michel Hazanavicius', 'The Descendants, Alexander Payne', 'Hugo, Martin Scorcese', 'Midnight in Paris, Woody Allen', 'The Tree of Life, Terrence Malick'], ['Albert Nobbs', 'Harry Potter and the Deathly Hallows Part 2', 'The Iron Lady'], ['The Adventures of Tintin, John Williams', 'The Artist, Ludovic Bource', 'Hugo, Howard Shore', 'Tinker Tailor Soldier Spy, Alberto Iglesias', 'War Horse, John Williams'], ['"Man or Muppet" from The Muppets', '"Real in Rio" from Rio']); #print a blank line say ""; #nested foreach loops to walk through each nominee in each category foreach my $category (@matrix) { #sets $tmp to 1 for each new category run $tmp = 1; #prints category name announcement print "==============================================================\n"; print "The nominees for $array[$count] are:\n\n"; #prints each nominee for the current category to screen, along with #that nominee associated number foreach my $nominee ( @$category ) { print "\t[$tmp] $nominee\n"; $tmp++; } #prints line offering user a choice of a write-in candidate print "\t[$tmp] Write In\n"; #prompts user to enter their selection, then chomps the input print "\nPlease enter your choice for $array[$count] now: "; $choice = <>; chomp $choice; #while loop to verify that user's choice is either the number #corresponding to a nominee for the current category, or the #write in candidate. while ($choice < 1 || $choice > $tmp) { print "I'm sorry, but $choice is not a valid option.\n"; #prompts user to re-enter a new selection, chomps input print "Please enter your choice for $array[$count] now: "; $choice = <>; chomp $choice; } #if/else block to check if the user's valid choice was the write-in #candidate option. If the choice was the write in candidate, prompts #user for their write-in, and stores the chomped input into the user #selection array. If the write in was not chosen, the string from #@matrix corresponding to their selection is stored in user selection #array. if ($choice == $tmp) { print "Please enter your write-in candidate: "; $selection[$count] = <>; chomp $selection[$count]; } else { $selection[$count] = $matrix[$count][$choice-1]; } #Thank user for their selection, echo their selection and the category print "\nThank you for selecting $selection[$count] as $array[$count].\n"; #increment variable $count, which is used to track the category $count++; #print blank line say ""; } #announcement thanking the user for their voting print "==============================================================\n"; print "Thank you for voting. Here is a summary of your votes:\n\n"; #reset value for $tmp $tmp = 0; #for loop to print summary of the user's final votes foreach my $vote (@selection) { print "$array[$count-$count+$tmp]:\n"; print "\t$vote\n\n"; $tmp++; }