in reply to setting env vars from hash fails for me

It appears that you're trying to set environment variables from inside of a script, so that they're visible to some other (or later) process. What you're doing instead is setting script variables, which are invisible outside of the processes memory (i.e., "printenv", which is another process, won't see them).

What you need to do is explained (very briefly) in perlvar, which explains that fork() will propagate changes to %ENV. So, instead of loading up %hash, change %ENV and then fork. Try forking to "printenv" as a quick test.

Replies are listed 'Best First'.
Re: Re: setting env vars from hash fails for me
by chromatic (Archbishop) on Aug 07, 2003 at 00:04 UTC

    Hmm, the following works for me on two Unix-like boxes (Mac OS X and GNU/Linux):

    use strict; %ENV = ( foo => 'bar '); system( 'printenv' );

    Looking in the code for system, it forks internally, which is what I'd expect. I wouldn't expect this to be very portable outside of Unix, though.

Re: Re: setting env vars from hash fails for me
by Limbic~Region (Chancellor) on Aug 06, 2003 at 23:27 UTC
    dws,
    I thought this too and almost replied, but I got distracted. It would be good to point out that while you can change "set" the environment that you fork (child process), you can't export it back to the parent. I was guessing that the OP was trying to do the equivalent of:
    $ perl -e 'cd /tmp' $ pwd /home/user $ echo "WTF?"

    Cheers - L~R

    Update: I can neither confirm nor deny it (without research anyway), but I heard this actually works on VMS. And while you can set the parent to read information from the child and set the parameters itself in the OS's I was originally referring to, the child is not actually doing it.