user1092042 user1092042 - 1 year ago 118
Perl Question

Setting the path in a perl program

I have a bluehost server setup and am trying to set the path in my perl program

print "Content-type: text/html\n\n";
my $output=`export PATH=\${PATH}:/usr/local/jdk/bin`;
my output1=`echo \$PATH`;
print $output1;

However it stil prints only the orginal $PATH. The /usr/local/jdk does not get added. Can anyone tell me what i am doing wrong?

Answer Source

You are creating a shell, executing a shell command that sets an environment variable in the shell, then exiting the shell without doing anything with the environment variable. You never changed perl's environment. That would be done using

local $ENV{PATH} = "$ENV{PATH}:/usr/local/jdk/bin";

Kinda weird to add to the end of the path, though.

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