Setup Environment variable using perl
environment, perl, tcsh, variables
Solution
$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
- the single quotes (or backslashing) is required on `echo $X1` to prevent `perl` to interpolate it itself.
- you can't change ENV of parent shell, see http://www.perlmonks.org/?node_id=684685
Problem
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.