This is a FAQ, found in Perl FAQ 8.
I {changed directory, modified my environment} in a perl
script. How come the change disappeared when I exited
the script? How do I get my changes to be visible?
Unix
In the strictest sense, it can't be done--the script
executes as a different process from the shell it was
started from. Changes to a process are not reflected
in its parent--only in any children created after the
change. There is shell magic that may allow you to
fake it by eval()ing the script's output in your shell;
check out the comp.unix.questions FAQ for details.
| [reply] |
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. | [reply] [d/l] [select] |
| [reply] |
Other posters are correct, it can't be done the way you're trying. However you could make your perl program print out what you want in VAR1 and in your shell script do:
export VAR1 = `/your/perl/script.pl`;
Hope that helps
| [reply] [d/l] |