Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

@INC , adding current script location

Status
Not open for further replies.

1DMF

Programmer
Joined
Jan 18, 2005
Messages
8,795
Location
GB
Hello folks,

Now I'm sure this has been asked but I've searched and can't find the answer....

I want to 'include' some modules in the current executing script directory.

I used to use "use lib qw ('absolute_path_to_cgi-bin')" but this becomes a pain in the butt, everytime the scripts are moved to a different server and the paths change.

is there a way of adding current directory to @INC, ive tried "use lib qw('./');" , dot , just slash, etc.. but I still get an error when trying to use the module saying it can't locate it.

I've tried googling and found
use lib glob('~/www/cgi-bin');
but that didn't work either.

I guess my syntax is wrong or something, can someone help.


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
OK - I've worked it out, after a lot of trawling and thanks to another post by PaulTeg pointing others to

which has [also see : findbin]

the working code is...
Code:
# Set path to current dir for user modules
use FindBin qw($Bin);
use lib "$Bin";

here is the additional info that might help someone
EXPORTABLE VARIABLES
$Bin - path to bin directory from where script was invoked
$Script - basename of script from which perl was invoked
$RealBin - $Bin with all links resolved
$RealScript - $Script with all links resolved

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top