Wong, Danny H. wrote:
> Hi Perl GURU's,
> In my Perl script, I read a text file and parse each line
> delimited by the first "=" character and create environment variables
> for each line of data. My question is: is there a way to expand the
> environment variable when trying to assign an environment variable value
> as part of the line of data?
>
>
> Example:
> Text file example:
> DB_ID="tst"
> #
> #
> MODIFIED_TIME=-3:0:0:0
> #
> CREATEDINQUALIFIER=created_in=$ENV{'LOCAL_DB_ID'}
>
>
> $ENV{'CREATEDINQUALIFIER'} gives me "created_in=$ENV{'LOCAL_DB_ID'}"
> value. I'll like it to receive the following value "created_in=tst";
>
> Any suggestions?
Quit CCing all the people - just write to the list.
You could use eval on it:
ue strict;
use warnings;
# Given:
$ENV{LOCAL_DB_ID} = 'tst';
my $key = 'CREATEDINQUALIFIER';
my $value = 'created_in=$ENV{\'LOCAL_DB_ID\'}';
print "\$key='$key', \$value='$value'\n";
# evaluate the value:
eval qq{\$ENV{$key} = "$value"}; # this handles your need
print "\$ENV{$key} = $ENV{$key}\n"
__END__
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs