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?
Not sure about what you're trying to accomplish, but seems like a task for FindBin::libs:
First, you have a simple syntax error - you're missing
;
after first line.my
variable should otherwise work fine inuse lib
.However, since all
use
directives are executed inBEGIN
block, your variable will be uninitialized at the moment you runuse
, so you need to put initialization inBEGIN
block too.Gives:
You can't, because the
use
directive is evaluated at compile time, while other variables are evaluated at runtime.If your lib is located somewhere relative to your original script, you can use the standard module
FindBin
: