Article 3707 of comp.lang.perl:
Xref: feenix.metronet.com comp.lang.perl:3707
Newsgroups: comp.lang.perl
Path: feenix.metronet.com!news.ecn.bgu.edu!mp.cs.niu.edu!ux1.cso.uiuc.edu!howland.reston.ans.net!gatech!destroyer!cs.ubc.ca!uw-beaver!fluke!dbc
From: dbc@tc.fluke.COM (Dan Carson)
Subject: Re: Setting DOS variables.  HELP!
Message-ID: <1993Jun25.171602.23425@tc.fluke.COM>
Organization: John Fluke Mfg. Co., Inc., Everett, WA
References: <lsloan.740685627@nova> <1993Jun24.204826.12248@wega.rz.uni-ulm.de>
Distribution: na
Date: Fri, 25 Jun 1993 17:16:02 GMT
Lines: 48

In article <1993Jun24.204826.12248@wega.rz.uni-ulm.de> heimann@felix.rz.fh-ulm.de (AT5 Holger Heimann) writes:
>Lance Sloan (lsloan@nova.gmi.edu) wrote:
>
>: I am able to read DOS environment variables, but I am having trouble
>: setting the variables to new values.  I am using Perl v4.0 pl19.
>
>: I make sure I have a DOS variable set before I run the program so that
>: I can be sure there is enough memory to hold the new value.  In the
>: program the variable contains the new value, but as soon as perl exits
>: the variable goes back to it's original value.  ...
>
>As far as I remember DOS (like UNIX) inherits the spawning processes
>environment to the child. In your case command.com calls perl, which 
>gets an exact *copy* of command.com's environment. Everything you change
>now will only concern perls environment. After perl exits it is
>discarded from memory with its (modified) environment and the old
>environment becomes active again.
>This is a feature, not a bug.
>By the way: No way to say 'system("set XX=yy")' or the like. You would
>just spawn another command.com and even perl wouldn't see any change in
>it's environment, not to talk about the original shell.
>
>There are (complicated) ways to circumvent this, but I cannot remember them.
>(You have to trace memory-control-block to the parent and seek for its
>environment, I guess)
>
>Correct me someone if I was wrong.
>
>hh

A batch file doesn't spawn a subprocess, so you could wrap your perl in
a .bat :

prog.bat:           prog.pl:
-----------         ----------
perl prog.pl        open(A,">blat.bat");
blat                print A "set foo=bar\n";
del blat.bat        close(A);


I tried this, it works on DOS.  This doesn't work on UNIX, but there is a
similar trick in csh using alias and eval `script`.

-- 
Dan Carson
dbc@tc.fluke.COM
John Fluke Mfg.
Everett, WA