Search code examples
perlvariablesenvironmenttcsh

Setup Environment variable using perl


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.


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