开发者

Setting a Perl variable as an environment variable

I'm trying to set a variable I previously set in a Perl script as an environment variable, but it seems to not realize the parameter I'm passing in is a variable and not the actual path I want.

For example, when I ru开发者_如何学编程n this:

$ENV{'ENV_VARIABLE'}='\'$file_path\'';
print($ENV{'ENV_VARIABLE'});

I only get:

'$file_path'

Is there any way I can tell it that what I'm passing in is actually a variable and not a literal string?


In Perl, single quoted strings do not interpolate variables. You want to use a double quote:

$ENV{'ENV_VARIABLE'}= "'$file_path'";

In that line, the rvalue is interpreted as q{'} . $file_path . q{'} where q{'} is a fancy way of writing '\'', which is a bit harder to read.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜