in reply to export environment variable from a perl program

Doesn't really have anything to do with perl, but with the process model most operating systems, if not all, use. That is, a child cannot affect its parent, only vice versa.

What I've done is create a "mkAlias" perl script which sets up my environment by printing shell commands to STDOUT. I then evaluate it in shell as:

eval `mkAliases`
Note that the shell pretty much removes all carriage-returns in the output (not quite true, but close enough), so separate each command from perl with a semicolon:
print qq[export VAR1="text";\n];
Hopefully you're using a shell that can do this - if you're using CMD.EXE on Windows, sorry, but the only solution is to have perl run CMD.EXE for you.

Replies are listed 'Best First'.
Re^2: export environment variable from a perl program
by Fletch (Bishop) on Feb 02, 2005 at 15:44 UTC
    That is, a child cannot affect its parent, only vice versa.

    And only before the parent creates the new process (after the fork you can't twiddle the child's environment, although if you're going to exec something else you can have code that twiddles things post-fork / pre-exec to the desired state).</pedantic>