Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Using perl module if env is enabled

by tobyink (Canon)
on Dec 09, 2019 at 16:07 UTC ( #11109883=note: print w/replies, xml ) Need Help??


in reply to Re: Using perl module if env is enabled
in thread Using perl module if env is enabled

A constant is usually better than a variable:

use constant HAVE_XYZ => !!$ENV{USE_XYZ}; use if HAVE_XYZ, 'XYZ'; ... if ( HAVE_XYZ ) { XYZ::foo(...) }

At it means that the if (...) stuff will be optimized away entirely when it's false. Also it will protect against $HAVE_XYZ being accidentally changed half way through running the process. (Of course, sometimes you do wish to start using XYZ later on by changing the variable, but that's probably less common.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2021-10-26 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (90 votes). Check out past polls.

    Notices?