Setup Environment variable using perl

user1793023 picture user1793023 · Nov 15, 2012 · Viewed 29.4k times · Source

I am trying to set environment variable using Perl. It should export this variable outside (in current shell) not just in the script.

I tried:

`setenv X1 /p/fsd`

system("setenv X1 /p/fsd") == 0 or die "failed:$?"

system command "setenv X1 /p/fsd" failed: -1

$ENV{"X1"} = "/p/fsd"; 

Nothing seems to be working.

If it matters i am using TCSH.

Answer

Gilles Quenot picture Gilles Quenot · Nov 15, 2012
$ENV{"X1"} = "/p/fsd"; 

is the right way.

Test in perlconsole :

Perl> $ENV{X1} = "/p/fsd";
/p/fsd

Perl> system('echo $X1');
/p/fsd
0

NOTE