Hi,
We have a configuration file from which we need to read and set some environment variables
if(open IPFH,"<$fname")
{
seek IPFH,0,0;
while (! eof IPFH)
{
my $con=<IPFH>;
chomp $con;
my($variable,$value)=split '=',$con;
chomp $variable;
chomp $value;
$ENV{"$variable"}=$value;
}
The issue is that Environment variables are not being set when we do this way; however when we explicitly specify
like this $ENV{'HOSTS'}=$value; it works.Is there a way to overcome this.
Thanks in advance
Robby
20040902 Edit by Corion: Added formatting
Im new to perl....
I guess my earler posting was not clear...
Heres what I tried
test1.pl....
my $value='abcdef';
$ENV{'PLATFORM'}=$value;
###### I belive this should set the environment variable PLATFORM
#just to confirm I called another perl program from with in this so if the environment is set then it should be reflected in the called program.
my $res=`perl c:/temp/test2.pl`;
print"\n result from test2.pl == $res\n";
test2.pl.....
my $val=$ENV{'PLATFORM'};
print "\n value of envir var platform= $val\n";
####### I belive this should now give abcdef
RESULTS:
#when test1.pl was run
result from test2.pl ==
value of envir var platform= abcdef
#### Thus I belive that the environment variables are actually set with in the life time of perl program test1.pl... please correct me if iam wrong.
########## Now my question ############
I need to do a similar stuff but the problem is that the environment variables which need to be set are available in a configuration file which needs to be read and then set, I tried to use a code as given in my earlier posting; however the problem was that
when ever I use
$ENV{"$variable"}="$value"; # not thing seems to be happening
$ENV{'PLATFORM'}="$value" ; # This seem to work
please advice...
Thanks
Robby
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.