in reply to setting ENV variables

Try this:

$ENV{'myVariable'} = 'myValue';
But it won't persist outside your program.

Replies are listed 'Best First'.
Re^2: setting ENV variables
by Fletch (Bishop) on Jun 22, 2004 at 14:41 UTC

    Erm, no. It will affect the process you set it in and any of its children; it won't affect the parent process (which is what you may be thinking of).

      What are you saying 'Erm, no' to?

      The %ENV hash is modifiable, it won't be reflected outside the program, and is in no way permanent.

        freebie:~ 619> perl -e '$ENV{FOO} = "Really?"; system( q/bash -c "echo + $FOO"/ )' Really?

        As I said, it affects the current process and any children spawned after the modification.

        Update: Rather than descend another level I'll reply here.

        My point is that modifications to %ENV are no more or less "persistent" than any other modification to a process' environment. Any modifications to the environment made in a shell startup file uses the same mechanism (mucking with the process' extern char **environ) and has the same scope (that process and its children); it's only by convention that they have a wider reach because they take effect further up the process tree.

        If you had an account which had one of the perl shells as its login shell (or even just a perl program for that matter) modifications to %ENV from whatever startup code it ran would be just as persistent and of the same scope as those made by zsh/bash/ksh/csh/... . Saying that the modifications to environ made by one process aren't persistent has as much meaning as saying that arguments passed to system() aren't persistent, as they're ephermal and specific to a particular process.

        And also note I'm speaking strictly in the POSIX-y OS sense; Wintendo does have a seperate mechanism where per-user and per-system environment settings can be made which are applied to all relevant processes.

Re^2: setting ENV variables
by vikee (Sexton) on Jun 23, 2004 at 07:42 UTC
    I need somthing that works both on unix and win from a perl. I think that it needs not to be persistent, just for the childs.
    
    thanks