How to debug a Perl BEGIN block or modue
Asked Answered
U

2

6

It has been over 2 years since my last confession [of ignorance].

In the not-too-recent past I have had the need to debug code within a BEGIN block or in a .pm module. I recall it's enabled by a certain variable; set that $variable = 1 in a BEGIN block in the program or in the module and "perl -d" suddenly applies within the BEGIN block (and, of course, the module).

My problem: I don't recall the name of that variable and the old code I have retrieved (from a disembodied drive) does not seem to have that setting. (A Google search for "debug perl module" returns a haystack.)

Please remind me: What was that variable?

Uhlan answered 20/7, 2023 at 21:43 Comment(0)
A
5

$DB::single = 1;

I think this is the var you want. It tells the debugger to stop at that point and let you debug. So if you put it as the first statement in the BEGIN you should be good to go.

See https://perlmaven.com/debugging-compile-time-code for more details. And apparently there are additional values for single: In perl, what is the difference between $DB::single = 1 and 2?

Algae answered 20/7, 2023 at 21:47 Comment(1)
Thanks scrappedcola. Our answers crossed paths but I will chase down your links for more knowledge.Uhlan
U
2

A friend just answered me my email but useful to post for posterity:

$DB::single = 1;

That's all there is to it. (Thanks, Steve!)

Uhlan answered 20/7, 2023 at 21:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.