debug stmts; cmd line define

Discussion in 'Perl Misc' started by Mike Ballard, Nov 20, 2005.

  1. Mike Ballard

    Mike Ballard Guest

    Been looking around usenet and am not finding what I'm looking for; how do
    I put statements in perl code for debug only (like printfs or whatever)
    and then actvate/define them from the command line? I know using cpp I
    can "-D<>" for ifdef statements and am looking for the same kind of thing
    for perl.

    Mike
    --
    Mike Ballard, Nov 20, 2005
    #1
    1. Advertising

  2. Mike Ballard

    Anno Siegel Guest

    Mike Ballard <dont_w@nt_spam.org> wrote in comp.lang.perl.misc:
    >
    > Been looking around usenet and am not finding what I'm looking for; how do
    > I put statements in perl code for debug only (like printfs or whatever)
    > and then actvate/define them from the command line? I know using cpp I
    > can "-D<>" for ifdef statements and am looking for the same kind of thing
    > for perl.


    Here is one way. In file "program", write

    print "debugging\n" if defined &DEBUG and DEBUG();

    Run with "perl program", this prints nothing.
    Run with "perl -Mconstant=DEBUG,1" program", it prints "debugging".

    Anno
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
    Anno Siegel, Nov 20, 2005
    #2
    1. Advertising

  3. Mike Ballard

    Mike Ballard Guest

    On Sun Nov 20, I was peacefully napping until Anno Siegel said:

    > Mike Ballard <dont_w@nt_spam.org> wrote in comp.lang.perl.misc:
    > >
    > > Been looking around usenet and am not finding what I'm looking for; how do
    > > I put statements in perl code for debug only (like printfs or whatever)
    > > and then actvate/define them from the command line? I know using cpp I
    > > can "-D<>" for ifdef statements and am looking for the same kind of thing
    > > for perl.

    >
    > Here is one way. In file "program", write
    >
    > print "debugging\n" if defined &DEBUG and DEBUG();
    >
    > Run with "perl program", this prints nothing.
    > Run with "perl -Mconstant=DEBUG,1" program", it prints "debugging".
    >


    Thank you very much; just what I was looking for...

    Mike
    --
    Mike Ballard, Nov 20, 2005
    #3
  4. Mike Ballard

    bugbear Guest

    Mike Ballard wrote:
    > Been looking around usenet and am not finding what I'm looking for; how do
    > I put statements in perl code for debug only (like printfs or whatever)
    > and then actvate/define them from the command line? I know using cpp I
    > can "-D<>" for ifdef statements and am looking for the same kind of thing
    > for perl.


    If you're doing anything of "significant" you might try:
    http://log4perl.sourceforge.net/

    BugBear
    bugbear, Nov 21, 2005
    #4
  5. Mike Ballard

    bugbear Guest

    Mike Ballard wrote:
    > Been looking around usenet and am not finding what I'm looking for; how do
    > I put statements in perl code for debug only (like printfs or whatever)
    > and then actvate/define them from the command line? I know using cpp I
    > can "-D<>" for ifdef statements and am looking for the same kind of thing
    > for perl.


    Addendum:

    http://www.perl.com/pub/a/2002/09/11/log4perl.html

    BugBear
    bugbear, Nov 21, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Achim Domma (Procoders)

    read input for cmd.Cmd from file

    Achim Domma (Procoders), Jun 3, 2005, in forum: Python
    Replies:
    2
    Views:
    8,068
    Peter Otten
    Jun 3, 2005
  2. Sarir Khamsi

    Interpreter-like help in cmd.Cmd

    Sarir Khamsi, Jun 9, 2005, in forum: Python
    Replies:
    4
    Views:
    371
    Bengt Richter
    Jun 26, 2005
  3. =?ISO-8859-1?Q?Sch=FCle_Daniel?=

    [exec cmd for cmd in cmds]

    =?ISO-8859-1?Q?Sch=FCle_Daniel?=, Mar 8, 2006, in forum: Python
    Replies:
    3
    Views:
    387
    Scott David Daniels
    Mar 8, 2006
  4. Diez B. Roggisch

    pydb remote debugging/cmd.Cmd over socket?

    Diez B. Roggisch, May 28, 2008, in forum: Python
    Replies:
    2
    Views:
    549
    Diez B. Roggisch
    May 29, 2008
  5. Diez B. Roggisch

    cmd.Cmd bug or at least docu-bug

    Diez B. Roggisch, May 29, 2008, in forum: Python
    Replies:
    1
    Views:
    342
    Michele Simionato
    May 29, 2008
Loading...

Share This Page