Exercise: Finding the Bug

This exercise shows you how to use the debugger. The program in Listing 12.1 has a problem—actually two. It's supposed to print these messages:

20 glasses of Lemonade on the wall
19 glasses of Lemonade on the wall
:
1 glass of Lemonade on the wall
0 glasses of Lemonade on the wall

But it does not. Your task is to type the program in Listing 12.1 and try to find the bugs. Neither of the bugs is a syntax problem—Perl's warnings are not triggered, and use strict prints no messages—but the debugger should make the bugs fairly obvious to find.

After you type the program, run Perl with the debugger to try to find the errors. Remember to print relevant variables and expressions occasionally and step through the function calls ...

Get SAMS Teach Yourself Perl in 24 Hours THIRD 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.