Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Conditional Interpretation?

by salva (Canon)
on Feb 01, 2006 at 14:54 UTC ( [id://527066]=note: print w/replies, xml ) Need Help??


in reply to Conditional Interpretation?

you are looking for assertions, unfortunatelly they only work on the unstable versions of perl. assertions::compat is also available but it requires you to test constants explicitelly as ...
dbg and expensive_test();

Another similar module is ctflags (that stands for "compile time flags"), it is overly complex with too many options... but for what you need:

In some place, at the beggining of your script, include this code to set flags from an environment variable:

use ctflags::parse ns => "myapp:debug", env=>'MYAPPDEBUG';
then in every module where you want to conditionally execute something add:
use ctflags prefix=>'dbg_', 'myapp:debug:*'; dbg_a and print "a flag is on\n"; dbg_b and print "b flag is on\n"; dbg_c and print "c flag is on\n";
Finally, if you call your script as
$ MYAPPDEBUG=ac perl myapp.pl
it will output
a flag is on c flag is on

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://527066]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-23 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found