A Third Example: The Cookie Monster

Here's one more example, just for fun. Back in the days of text-only computer terminals, there was a practical-joke program that floated around for a while called “the cookie monster.” The cookie monster program would lock up your terminal and endlessly prompt you to “Give me a cookie.” (or, “I WANT A COOKIE.” or some variation), and no matter what you typed, it would always insist it wanted a cookie. The only way out of the program was to actually type cookie, something that only seemed obvious after you had spent an hour trying to get out of the program.

Listing 1.3 shows a simple Perl version of the cookie monster program.

Listing 1.3. The cookie.pl Script
 1: #!/usr/local/bin/perl -w 2: # 3: # Cookie Monster ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.