An Example: A Guessing Program

Back in Lesson 6, there was an example program that implemented a number guessing game. In this example, we're going to turn things around and let the program try to guess what you entered. This program illustrates how you can use regular expressions to break down strings and figure out what they are.

The structure of the program is simple. It consists of an infinite while loop that continues to iterate until the last function is called. If the user enters 'q' on a line by itself, then the program will exit. Otherwise, it applies a number of regular expressions to the user's input to try to determine what sort of data was entered. If the input does not match any of the expressions, then a message indicating that ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

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