O'Reilly logo

Sams Teach Yourself Perl in 21 Days, Second Edition by Rafe Colburn, Laura Lemay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required