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;
ifis a separate module (strictly a pragma) that takes the rest of the line as parameters.libis also a separate pragma. Take a look at the documented syntaxuse if CONDITION, MODULE => ARGUMENTSand you will see that what you should be writing iswhich works fine.