Perl FAQ 5.24: I {changed directory, modified my environment} in a perl script. How

Perl FAQ 5.24

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?

In the strictest sense, it ``can't'' be done. However, there is special shell magic which may allow you to do it. I suggest checking out comp.unix.shell and reading the comp.unix.questions FAQ.

When perl is started, you are creating a child process. Due to the way the Unix system is designed, children cannot permanently affect their parent shells.

When a child process is created, it inherits a copy of its parents environment (variables, current directory, etc). When the child changes this environment, it is changing the copy and not the original, so the parent isn't affected.

If you must change the parent from within a perl script, you could try having it write out a shell script or a C-shell script and then using ``. script'' or ``source script'' (sh, Csh, respectively)


Other resources at this site: