2

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?

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.