beans
beans

Reputation: 364

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 run 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?

Upvotes: 2

Views: 1386

Answers (1)

Eric Strom
Eric Strom

Reputation: 40152

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.

Upvotes: 8

Related Questions