質問

If I have a script.pl for example in the path C:\folder1\folder2 when I use Cwd it will of course return C:\folder1\folder2 as my current working directory. I was wondering though if I could change my working directory within my script.pl using

chdir "C:/folder1"; 

so I can now look in C:\folder1 for any modules I need.

役に立ちましたか?

解決

Yes, you can do exactly that, but it won't change where use and require look for the modules you are including. All it will affect is where file operations like open will look for files specified with a relative path.

What you need is the lib pragma, like this

use lib 'C:/folder1';

at the head of your program. This will add the directory to @INC which is the built-in array of directories that Perl searches for included modules.

他のヒント

You can, but you shouldn't. Instead use the lib module to include alternative module roots:

use lib 'C:/folder1';
use My::Module; # which is in C:/folder1/My/Module.pm
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top