Hitesh Ray ([EMAIL PROTECTED]) wrote:
> >
> 
> Hi All,
> 
> I am required to modify an Environment variable from one value to another
> using perl script. I can access the env. variables in the perl
> script using ENV. How can i modify so that when I exit my perl script -- the
> env. variable has new value.

You can't.  That's not a perl but a Unix thing.

The environment gets inherited from the parent process to the child,
that can then do some modifications and eventually start another child,
but you can't modify the environment backwards the chain.

What you can do, however, is creating some output that the shell that
calls you can evaluate after your program finishes.  I'm using something
like that to avoid cluttering my PATH while still keeping it in the
right order:

- Note: that's a bash and not a bourne-shell function:

    ---------- snip from .bash_profile ----------
    cleanpath () {
        export PATH=`echo $PATH | \
            perl -anF: -e '$,=":"; print map { $had{$_} ? () : ($had{$_}=$_) } @F;'`
    }

    cleanpath
    ---------- snip from .bash_profile ----------

So, in the end, your program could print a new environment that your
shell could "eval" - see sh(1) for how to use that.

-- 
                     If we fail, we will lose the war.

Michael Lamertz          | [EMAIL PROTECTED] / [EMAIL PROTECTED]
    Nordstr. 49          | http://www.lamertz.net
    50733 Cologne        | Work: +49 221 3091-121
    Germany              | Priv: +49 221 445420 / +49 171 6900 310

Reply via email to