in reply to Setting environment variables by reading them from a configuration file

Are you expecting the environment values to still be true after the script has run? If so, this will not work. The values can be set during the script but once it exits, the values disappear. Other people have noted this in your other posting.

use Data::Dumper; ## First show the current environment print "What does \%ENV look like now:\n"; $Data::Dumper::Purity=1; print Data::Dumper->Dump([\%ENV], ['*ENV']); ## now we manually add an element to the ENV hash $key="JUST_A_TEST"; $value='just_a_value'; $key_1='ANOTHER_SILLY_KEY'; $ENV{'EXAMPLE'}='12345_test'; $ENV{$key}='yes_this_is_a_value'; $ENV{'EXAMPLE4'}=$value; $ENV{$key_1}=$value; ## Show the current environment after setting manually print "What does \%ENV look like now:\n"; $Data::Dumper::Purity=1; print Data::Dumper->Dump([\%ENV], ['*ENV']); ## Get the key/value pairs from DATA open IN, "environment.txt" or die "Cannot open $input. $!"; foreach $pair (<DATA>) { ($key,$value)=split(/=/,$pair); $ENV{$key}=$value; }#close foreach ## First show the current environment print "What does \%ENV look like now:\n"; $Data::Dumper::Purity=1; print Data::Dumper->Dump([\%ENV], ['*ENV']); #the following data is read from DATA but could be put into "environme +nt.txt" and used from there too. __DATA__ EXAMPLE2=test_test_test_1234567890 EXAMPLE3=a_very_modern_major_sample_of_a_has_value
  • Comment on Re: Setting environment variables by reading them from a configuration file
  • Download Code