opensourcer has asked for the wisdom of the Perl Monks concerning the following question:

i want to have warnings/trace based on cmdline Options.
xxx.pl --help -d displays complete debuging statements. -e display db debuging statements. -f displays only errors.
i don't know whether it's works or not
sub main { DEBUG: "now entering into main\n"; DB_DEBUG: "in main\n"; ERRORS: "start of main\n"; }
the condition should be something like this, if -d should print all the statement of DEBUG.
i'm not asking to write a code for me, i guess is there is a modules for this, i have done years back, and now im not able to recall it, if any 1 knows about that modules. plz let me know.

Replies are listed 'Best First'.
Re: DEBUG levels <perl formats>
by osunderdog (Deacon) on Oct 19, 2006 at 07:49 UTC

    I would highly recommend Log::Log4perl

    You would have to translate your commandline switches into a constructor for a logger instance.

    Hazah! I'm quitting!

    $g = "FSF SUCKS"; $g =~ s/F/C/g; print $g;
Re: DEBUG levels <perl formats>
by blazar (Canon) on Oct 19, 2006 at 19:09 UTC
    i want to have warnings/trace based on cmdline Options.
    xxx.pl --help -d displays complete debuging statements. -e display db debuging statements. -f displays only errors.

    The way I'd doit is like thus:

    1. map your cmd lines args into suitable flag variables;
    2. just add some warn statements complete of an if $flag modifier.

    But that's not the whole story: for a more integrated approach write a, say, warning() sub which accepts a first argument that is to describe a severity level. Then your command line arguments may set a suitable "global" $severity variable, and warning() should either emit the warning (the other arguments) or ignore it althogether depending on whether the severity is equal or lower than that set by $severity.

    But that's not the whole story yet: for some computation intensive subs where performance may matter, I would probably alias them into the stash depending on the severity level, but that's an extreme corner case.