Use lib with if pragma in perl

In perl we can do:

use lib LIST;

include a list of paths in @INC. Similarly, we can do:

use if CONDITION, MODULE => ARGUMENTS;

to enable the module conditionally.

Is it possible to make a combination of both, something like

use lib if CONDITION, LIST;

include a conditional list of paths. This does not work.

Edit: Sorry, but I still can't get it to work. This is what I do, but not work. Could you 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; 
+6
source share
1 answer

if is a separate module (strictly a pragma) that takes the rest of the string as parameters. lib also a separate pragma. Take a look at the documented syntax use if CONDITION, MODULE => ARGUMENTS and you will see what you should write

 use if CONDITION, lib => LIST; 

which works great.

+10
source

Source: https://habr.com/ru/post/910341/


All Articles