You can only change the environment of your own process and yet-to-be-created children.
In your code, you launch sh, tell the process to change one of its environment variables, and then the process exits along with environment.
The following will set the env var for the Perl process and any child it launches (via system, for example):
$ENV{CLASSPATH} = "$ENV{CLASSPATH}:/usr/users/private";
If you want to change the parent's environment, you'll need to send commands to the parent process that it understands. Here's an example for Windows systems:
>type script.bat
@echo off
set testa=
set testb=
echo testa=%testa%
echo testb=%testb%
for /f "usebackq delims=" %%f in (`perl script.pl`) do %%f
echo testa=%testa%
echo testb=%testb%
>type script.pl
print("set testa=abc\n");
print("set testb=def\n");
>script
testa=
testb=
testa=abc
testb=def
|