|P is for Practical|
using "require" problemby gauss76 (Beadle)
|on Sep 26, 2017 at 07:51 UTC||Need Help??|
gauss76 has asked for the wisdom of the Perl Monks concerning the following question:
I have the following problem and don't know how to resolve it.
Basically, I have a perl .pl file (main.pl) that requires another .pl file (routines.pl) in order to work correctly (everything running on a Linux machine). The files are both in the same folder and I currently use the following syntax in the file main.plrequire "./routines.pl";
This works fine if I run main.pl from the folder that contians the two files. However if I run the program from a different folder with, say, the commandperl /home/user/code/main.pl
Then I get an error saying "can't locate ./routines.pl.
I know that I can change the "require" statement to:require "/home/user/code/routines.pl"
However, for me, this is not an option as I need to copy the code to another Linux system where the containing folder will be different (the two files will still be in the same folder)
So, my question: Is there any way to use the same "require" statement so that I can run my program from any folder with the commandperl /home/user/code/main.pl
where the folder for the code (/home/user/code/main.pl) can change?
Please let me know if anything is not clear.
Many thanks for any help on this