Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use a variable in lib Path?

I would like to use the $var variable in lib path.

my $var = "/home/usr/bibfile;"

use lib "$var/lib/";

However when I do this it throws an error.

I'd like to use use lib "$var/lib/";instead of use lib "/home/usr/bibfile/lib/";.

How can I assign a variable, so that it can be used in the setting of lib modules?

like image 420
Sourcecode Avatar asked Dec 19 '12 10:12

Sourcecode


People also ask

How do I add a variable to a PATH?

To add a path to the PATH environment variableIn the System dialog box, click Advanced system settings. On the Advanced tab of the System Properties dialog box, click Environment Variables. In the System Variables box of the Environment Variables dialog box, scroll to Path and select it.

How is PATH variable used?

The PATH variable is an environment variable containing an ordered list of paths that Linux will search for executables when running a command. Using these paths means that we don't have to specify an absolute path when running a command.

What is LIB environment variable?

The LIBPATH environment variable tells the shell on AIX® systems which directories to search for dynamic-link libraries for the INTERSOLV DataDirect ODBC Driver. You must specify the full path name for the directory where you installed the product.


1 Answers

Variables work fine in use lib, well, just like they do in any string. However, since all use directives are executed in BEGIN block, your variable will be not yet initialized at the moment you run use, so you need to put initialization in BEGIN block too.

my $var;
BEGIN { $var = "/home/usr/bibfile"; }
use lib "$var/lib/";

use Data::Dumper;
print Dumper \@INC;

Gives:

$VAR1 = [
      '/home/usr/bibfile/lib/',
      # ... more ...
    ];
like image 196
Oleg V. Volkov Avatar answered Nov 10 '22 08:11

Oleg V. Volkov