In perl, we can do:
use lib LIST;
to include a list of paths in @INC. Similarly, we can do:
use if CONDITION, MODULE => ARGUMENTS;
to include a module conditionally.
Is it possible to do a mix of both, something like
use lib if CONDITION, LIST;
to include a list of paths conditionally. This doesn't seem to work.
Edit: Sorry, but I can't still get it working. This is how I am doing but its not working. Can you please suggest what is wrong?
use Data::Dumper;
BEGIN {
my $env=$ENV{'ENV'};
use if $env eq 'OLD', lib => '/home/vivek/OLD';
use if $env eq 'NEW', lib => '/home/vivek/NEW';
}
print Dumper \@INC;
if
is a separate module (strictly a pragma) that takes the rest of the line as parameters. lib
is also a separate pragma. Take a look at the documented syntax use if CONDITION, MODULE => ARGUMENTS
and you will see that what you should be writing is
use if CONDITION, lib => LIST;
which works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With