http://qs1969.pair.com?node_id=931273

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

This is my dos batch script:
@echo off @set SCRIPTDIR=%~dp0 @for /f %%I in ("%SCRIPTDIR%\.") do @set BingApps=%%~dpI @for /f %%I in ("%BingApps%\.") do @set BingAppsHome=%%~dpI @for /f %%I in ("%BingAppsHome%") do @set myDRIVE=%%~dI @set SCRIPTDIR=%SCRIPTDIR:~0,-1% set SCRIPTDIR set BingApps @for /f %%I in ("%BingAppsHome%") do @set BingTcEnv=%%~nI @set TEMP=%DRIVE%\temp @set THIS_HOME=%DRIVE%\thisHome @set thisRoot=%BingAppsHome%\thisRoot @set thisData=%BingAppsHome%\thisData set thisData echo doneDosTest
This is my perl script
use strict; use warnings; use File::Find; use File::Spec; use File::Path; use File::Copy; use File::Basename; use Cwd; my $scriptDir = cwd; #------------------------------------------ my $operatingSystem = $^O; my $windows = "MSWin32"; my $unix = "hpux"; print "Running under ${operatingSystem} environment.\n\n"; my $pathSeparator = ""; if ( $operatingSystem eq $windows ) { $pathSeparator = "\\"; } else { $pathSeparator = "/"; } #------------------------------------------ #execute the environment variables script if ( $operatingSystem eq $windows ) { system("$scriptDir/dosTest.bat"); } else { system("$scriptDir/unixTest.sh"); } #---------------------------------------------- $ENV{'ksENV'} = "c:/temp"; $ENV{'script_dir'} = "$ENV{'ksENV'}/bin"; my $someFile = "$ENV{'ksEnv'}/bin/someFile.txt"; open theFile, $someFile or die $!; while (my $record = <theFile>) { print $record; } close(theFile); print "\n$ENV{script_dir}"; print "\n$someFile"; print "\n$ENV{THIS_HOME}"; print "\n$ENV{thisRoot}";
When the perl script is executed the final two print statements for printing the environment variables set by the dos script return this: Use of uninitialized value $ENV{"THIS_HOME"} in concatenation (.) or string at perltest.pl line 50.... The 'set' statements in the dos script execute fine..they return the value of the environment variables that I expect to see. I would've expected the environment variables set by the dos script to stay put in the cmd window - but they don't. Please advise on what I could be doing wrong here. Thanks...