Perl Program 3, Madlibs Madlibs is a word game involving short stories that are completed by a player. The player is told what kind of words to provide but not how they will be used in the story. The results are variously amusing, silly, or nonsensical. Here's an example. Story Template Strangeness in Cars I once owned a [noun] that was [adjective] only when in a [Make-of-car]. Some [plural-noun] thought, [adverb], that this was [another-adjective], but what did they [verb]. Anyway, now I am [comparative], and don't [verb] so much, even when in [make-of-car] cars. Do you think that's [another-adjective], or should I [strange-action-verb]? User Words The player must provide replacements for the words in square brackets. Here, the words are noun, adjective, make-of-car, plural-noun, adverb, another-adjective, verb, comparative, strange-action-verb. Note that if the same word appears twice in brackets, it represents only one word and the same substitution is made in all places that the word occurs. Suppose the player provides the following substitute words. noun => jar adjective => large make-of-car => REO plural-noun => combs adverb => lightly another-adjective => smaller verb => dance comparative => larger strange-action-verb => prance The resulting story would be. Strangeness in Cars I once owned a jar that was large only when in a REO. Some combs thought, lightly, that this was smaller, but what did they dance. Anyway, now I am larger, and don't dance so much, even when in REO cars. Do you think that's smaller, or should I prance? You'll find many more examples of madlibs on this link. There are two template files, "Strangeness of Cars" and "Vacation" that you can use for testing. Create another of your own design.
Deliverables: The program Create a Perl script to play madlibs. Call it madlibs.pl. The script should be designed to run with one command line parameter providing the name of the story template file. Under Unix, you could then give the command $ [url removed, login to view] [url removed, login to view] to use the [url removed, login to view] story template. The program should prompt the user for each replacement word and build a hash of the resulting word pairs. The brackets are for you to identify what to replace but should not be shown to the user. After you have all the replacements, print the resulting story using the same line arrangement as in the original template. Your code must include at least two user functions. At least one function must have arguments that are copied into variables. You must use pattern matching with substitution to extract the words to replace and to do the replacement. You may not use the substr() function. Five Point Bonus: If the bracketed word starts with an upper-case letter, print the replacement with the first letter upper-case even if the user types the replacement with a lower-case letter but do not change an initial upper-case letter to lower case. If the same word is used two or more times, capitalize it only when the word in the template is capitalized. This must be implemented using pattern matching and substitution commands. What to turn in Submit your program script file, [url removed, login to view], both on paper and electronically using hwroy. Submit a sample of the program execution on paper only
Windows XP Perl