Chapter 6. Debugging

Of course everyone writes perfect code on the first try, but on those rare occasions when something goes wrong, and you’re having trouble with your Perl script, there are several things you can do:

  • Run the script with the -w switch, which prints warnings about possible problems in your code.

  • Use the Perl debugger.

  • Use another debugger, or a profiler such as the Devel::DProf module.

The major focus of this chapter is the Perl debugger, which provides an interactive Perl environment. The chapter also describes the DProf module and the dprofpp program that comes with it; together they can provide you with a profile of your Perl script. If you’ve ever used any debugger, and you understand concepts such as breakpoints and backtraces, you’ll have no trouble learning to use the Perl debugger. Even if you haven’t used another debugger, the command descriptions and some experimenting should get you going.

Get Perl in a Nutshell, 2nd 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.