O'Reilly logo

Computer Science & Perl Programming by Jon Orwant

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

Chapter 70. Debugging Perl Programs with -D

Chip Salzenberg

Easy debugging of Perl programs has been a standard feature of Perl for a very long time. There’s the -w flag which warns you about potential errors, and for more serious bug hunting, there’s the Perl debugger. Perl’s debugger—written in Perl!—is invoked with the -d flag.

This article is not about the -d flag.

This article is about something much more wizardly: the -D flag. This flag is your gateway to a set of debugging behaviors inside Perl’s guts. If you’re up against a tough bug and you can’t figure out where it’s coming from, -D may be just what the sergeant ordered.

Not all Perl binaries let you use the -D flag. The code to support it makes the Perl binary a bit larger and slows down execution just a hair. Since Larry is loathe to enlarge or slow Perl, the binary includes support for -D only if it was explicitly compiled with the -DDEBUGGING option, which is turned off by default.

You can tell whether your Perl was compiled with -DDEBUGGING by examining the output of perl -V. The last section of perl -V output is “Characteristics of this binary”. If you have a fairly recent version of Perl, then the first line in that section will be “Compile-time options”; if that line includes the word DEBUGGING, then your Perl supports -D.

What -D Does for You

Perl is too complex and juggles too many eggs to have just one debugging flag. And in fact -D isn’t really just one flag. Rather, it’s a prefix that lets you turn on multiple debugging ...

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