Home arrow Perl Programming arrow Page 2 - Perl Basics: Writing and Debugging Programs

The Perl Debugger - Perl

In this third part of a three-part article series on the basics of Perl programming, you'll learn how to use escape sequences in your programming, and how to use the Perl debugger. This article is excerpted from chapter one of the book Beginning Perl, Second Edition by James Lee (Apress; ISBN: 159059391X).

  1. Perl Basics: Writing and Debugging Programs
  2. The Perl Debugger
By: Apress Publishing
Rating: starstarstarstarstar / 0
January 18, 2012

print this article



One thing you’ll soon notice about programming is that you’ll make mistakes; mistakes in programs are called bugs. Bugs are almost entirely unavoidable, and creating bugs does not mean you’re a bad programmer. Windows 2000 allegedly shipped with 65,000 bugs, but then that’s a special case, and even the greatest programmers in the world have problems with bugs. Donald Knuth’s typesetting software TeX has been in use for more than 20 years, and Professor Knuth was still finding bugs until a couple of years ago. Who can tell when all the bugs are out anyway?

While we will be showing you ways to avoid getting bugs in your program, Perl provides you with a tool to help find and trace the causes of bugs. Naturally, any tool for getting rid of bugs in your program is called a debugger. Mundanely enough, the corresponding tool for putting bugs into your program is called a “programmer.”

To use the debugger, start your program with the-doption as in

$ perl -d myprogram.pl

See perldoc perldebugfor information about the debugger.


We’ve started on the road to programming in Perl, and programming in general. We’ve seen our first piece of Perl code, and hopefully, you were able to get it to run.

Programming is basically telling a computer what to do in a language it comprehends. It’s about breaking down problems or ideas into byte-sized chunks (as it were), and examining what needs to be done in order to communicate them clearly to the machine.

Thankfully, Perl is a language that allows us a certain degree of freedom in our expression, and, so long as we work within the bounds of the language, it won’t enforce any particular method of expression on us. Of course, it may judge what we’re saying to be wrong, because we’re not speaking the language correctly, and that’s how the majority of bugs are born. Generally though, if a program does what we want, that’s enough—TMTOWTDI.

We’ve also seen a few ways of making it easy for ourselves to spot potential problems, and we know there are tools that can help us if we need it. We have examined a little bit of what goes on inside a computer, how it sees numbers, and how it sees characters, as well as what it does to our programs when and as it executes them.


  1. Create a program newline.pl containing print "Hi Mom.\nThis is my second program.\n". Run this and then replace\nwith a space or a return and compare the results.
  2. Download the code for this book from the publisher’s website at www.apress.com.
  3. Have a look around the Perl homepage at www.perl.com.

>>> More Perl Programming Articles          >>> More By Apress Publishing

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Perl Turns 25
- Lists and Arguments in Perl
- Variables and Arguments in Perl
- Understanding Scope and Packages in Perl
- Arguments and Return Values in Perl
- Invoking Perl Subroutines and Functions
- Subroutines and Functions in Perl
- Perl Basics: Writing and Debugging Programs
- Structure and Statements in Perl
- First Steps in Perl
- Completing Regular Expression Basics
- Modifiers, Boundaries, and Regular Expressio...
- Quantifiers and Other Regular Expression Bas...
- Parsing and Regular Expression Basics
- Hash Functions

Developer Shed Affiliates


Dev Shed Tutorial Topics: