shreedarasp has asked for the wisdom of the Perl Monks concerning the following question:

I have a unique requirement, in one of my MySql table i have a field called 'input_folder' and i have defined its value as '$ENV{INP_DIR}' and in my windows profile, i have defined this ENV variable and valu is set as "C:/tmp/setup". my idea is to read this field from SQL table and substitute to windows ENV variable. But when i read this from my perl script i get it as $ENV{INP_DIR} itself and NOT substituted to its true ENV value. is there a way to read the actual value? i tried with $t = $v->{input_folder}; $t2 = eval $t; but it returns just blank. i tried it with $t3 = "$t/xx" still did not work. any suggestion? thanks for replies, i have number of fields which has similar values. so i wanted it to work this way. However Corion's tips was usefull and workable. while doing experiment i found a way. In mySQL table i have modified the value from $ENV{INP_DIR} to "$ENV{INP_DIR}" double quotes included in value itself and it worked.

Replies are listed 'Best First'.
Re: evaluating field from mySQL
by Corion (Patriarch) on Sep 15, 2011 at 06:57 UTC

    How about extracting the string and then accessing %ENV with it?

    my $db_str = '$ENV{INP_DIR}'; $db_str =~ s/\$ENV\{([^}]*)\}/$ENV{$1}/ge; print $db_str;

    Also see eval, but that will allow anybody to run arbitrary code.

Re: evaluating field from mySQL
by onelesd (Pilgrim) on Sep 15, 2011 at 07:04 UTC

    Am I missing something? If you know the ENV variable you want is INP_DIR, why not just use it directly?

    my $dir = $ENV{INP_DIR} ;
Re: evaluating field from mySQL
by Anonymous Monk on Sep 15, 2011 at 13:32 UTC
    Be sure that you put this construction in double quotes not single ones. (Double-quotes cause interpolation; single-quotes suppress it.) And be sure also that you are sending the value (in an insert or update query) using a query-parameter.
      thanks for replies, i have number of fields which has similar values. so i wanted it to work this way. However Corion's tips was usefull and workable. while doing experiment i found a way. In mySQL table i have modified the value from $ENV{INP_DIR} to "$ENV{INP_DIR}" double quotes included in value itself and it worked.