Home > Archive > PERL Beginners > January 2006 > debug code in BEGIN{} block
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
debug code in BEGIN{} block
|
|
| Ken Perl 2006-01-20, 3:56 am |
| How to debug code in BEGIN{} block?
--
perl -e 'print unpack(u,"62V5N\"FME;G\!E<FQ`9VUA:6PN8V]M\"\@``
")'
| |
| Paul Lalli 2006-01-20, 6:59 pm |
| Ken Perl wrote:
> How to debug code in BEGIN{} block?
I'm assuming what you mean is "How can I use the Perl debugger to look
at code within a BEGIN block?". Honestly, before I read this post, I
didn't realize that the debugger skips over BEGIN{} code. So I looked
at the documentation:
perldoc perldebug
And then I searched for the word "BEGIN". The very first result is
this paragraph:
If you have compile-time executable statements (such as code
within BEGIN and CHECK blocks or "use" statements), these
will not be stopped by debugger, although "require"s and
INIT blocks will, and compile-time statements can be traced
with "AutoTrace" option set in "PERLDB_OPTS"). From your
own Perl code, however, you can transfer control back to the
debugger using the following statement, which is harmless if
the debugger is not running:
$DB::single = 1;
A quick test showed me that adding that line as the first line of the
BEGIN block does indeed cause the debugger to halt there, rather than
at the end of the BEGIN block.
Please make a cursory attempt to help yourself by reading the built-in
documentation before asking thousands of people around the world to
read it to you.
Paul Lalli
| |
| Tom Phoenix 2006-01-20, 6:59 pm |
| On 1/19/06, Ken Perl <kenperl@gmail.com> wrote:
> How to debug code in BEGIN{} block?
You can make a "permanent breakpoint" by assigning to $DB::single,
even during a BEGIN block.
$DB::single =3D 1 if $fred < 7;
There's more detail in the perldebug manpage. Hope this helps!
--Tom Phoenix
Stonehenge Perl Training
|
|
|
|
|