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
In reply to Re: Setting environment variables by reading them from a configuration file
by nimdokk
in thread Setting environment variables by reading them from a configuration file
by robby123
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |