Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use lib with if pragma in perl

Tags:

perl

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;
like image 218
Vivek Avatar asked Mar 09 '12 11:03

Vivek


1 Answers

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.

like image 112
Borodin Avatar answered Oct 29 '22 16:10

Borodin