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

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.