Sprad has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to convert some nasty Windows batch scripts into Perl, but I ran into a problem.

I know that when I run a Perl program, it gets its own environment, so changes made to variables disappear after the program's done. That's fine, I can live with that. But I just found out by experimentation (see code) that each call to system() also gets its own environment. Bugger.

Is there a way to force calls to system() to use the same environment as the main Perl program? If possible, I'd like to do this without modules outside the main Perl install, for easier distribution to those who'll be using it.

Here's my test code. When I run it, monkeylikes is always reported to be "bananas".

$ENV{'MonkeyLikes'} = "bananas"; print "$ENV{'MonkeyLikes'}\n"; system("echo %monkeylikes%"); system("set monkeylikes=flinging poo"); system("echo %monkeylikes%");
--- I'm too sexy for my .sig.