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
This article is not about the
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
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 ...