Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: using constants to trigger debug code

by liz (Monsignor)
on Jun 04, 2004 at 20:03 UTC ( #361184=note: print w/replies, xml ) Need Help??


in reply to using constants to trigger debug code

To further what the other monks already said.

When using constants with debugging, I'm usually using an environment variable to signal the level of debugging info required, with variations on the following code:

BEGIN { my $level = $ENV{'FOO_DEBUG'} || 0; eval "*Foo::DEBUG = sub () {$1}" if $level =~ m#^(\d+)$#s; } #BEGIN if (Foo::DEBUG) { print "We're debugging\n"; }
If this code is run with -MO=Deparse, you get:
sub BEGIN { my $level = $ENV{'FOO_DEBUG'} || 0; eval "*Foo::DEBUG = sub () {$1}" if $level =~ /^(\d+)$/s; } '???';
If you set the environment variable FOO_DEBUG to 1, you get:
sub BEGIN { my $level = $ENV{'FOO_DEBUG'} || 0; eval "*Foo::DEBUG = sub () {$1}" if $level =~ /^(\d+)$/s; } do { print "We're debugging\n" };

Hope this helps.

Liz

Replies are listed 'Best First'.
Re^2: using constants to trigger debug code
by adrianh (Chancellor) on Jun 04, 2004 at 20:15 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://361184]
help
Chatterbox?
[Lady_Aleena]: I wish I could have helped you further but I've never uploaded to cpan or metacpan so I don't know much.
[Lady_Aleena]: If metacpan had a pod checker too, I could check a pod I wrote with a module link there.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2017-05-27 04:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?