in reply to Using perl module if env is enabled
In my experience, conditionally loading a module (like Corion and tobyink already showed) isn't always the only thing going on, since later on in your code you might want to use functions from that module conditionally, based on whether it was loaded in the first place. Personally, I prefer to set a global variable, something like this:
our $HAVE_XYZ; BEGIN { $HAVE_XYZ = !!$ENV{USE_XYZ} } use if $HAVE_XYZ, 'XYZ'; ... if ( $HAVE_XYZ ) { XYZ::foo(...) }
Also, note that BEGIN is uppercase, not begin {...}.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Using perl module if env is enabled
by tobyink (Canon) on Dec 09, 2019 at 16:07 UTC |
In Section
Seekers of Perl Wisdom