asdf asdf - 2 years ago 65
Perl Question

Calling script with the same @INC as the parent script

I want to call an external script with

system ($script)
do $script
. In my @INC i have some specific modules which I import. How can I call the
and transfer it the same

#importing some libs
$script = "path_to_script";

system ($script);

And I get the Error :

Can't locate [email protected] in @INC...

Answer Source

The easiest way is probably to set the PERL5LIB environment variable. That will add a list of directories to the child process's @INC array

Your code would look something like

$ENV{PERL5LIB} = join ':', @INC;

system $script;

This has the disadvantage that the standard directories will also be added to @INC. It shouldn't cause any problems, but it would be best to set PERL5LIB to just the custom directories if you know them at that point.

Note also that perl will ignore PERL5LIB if you are running under the taint flag.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download