Exercise: Playing a Little Game

This hour has really been full of catch-22's: familiar operators behaving differently depending on context, a handful of new operators and functions, and quite a few new rules to remember about syntax. To keep you from developing any hang-ups, I've added this exercise, which puts your knowledge of arrays and lists to good use—a game.

Using your text editor, type the program from Listing 4.2 and save it as Hangman. Be sure to make the program executable according to the instructions you learned in Hour 1.

When you're done, try running the program by typing the following at a command line:

perl Hangman

Listing 4.3 shows a sample of the Hangman program's output.

Listing 4.2 Complete Listing of the Hangman Program ...

Get Sams Teach Yourself Perl in 24 Hours now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.