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

I am aware Perl interprets a single quoted string differently than a double quoted string.
For example
my $color=" blue"; my $string='I like the color $color'; print "$string\n";
output =I like the color $color
if we use a dubble quoted string $string =”I like the color $color”;
then the output would be “I like the color blue”

Basic Perl 101
Here is the problem…
I would like to pull a string from an xml file using XML::Simple. As far as I can tell XML::Simple pulls the string as a single quoted string so my variable imbedded in the string is incased in a single quoted string

I guess I could use some type of regular expression substitution but I am not sure what variables I want to use in the future.
Is there anyway to force Perl to re-interpret the string as a quoted string?
Or any Ideas on how to solve this issue?

Thank You.

Replies are listed 'Best First'.
Re: interpret variable in a single quoted string
by kennethk (Abbot) on Feb 08, 2011 at 21:07 UTC
    It is not that single- and double-quoted strings are different beasts, but different ways of inputting data. Once the data is in there, it's just a string. In your case, what you want to do is usually referred to as double-interpolating. You can accomplish this with eval, but only use eval on trusted data. See Double Interpolation of a String for an example, care of chromatic.
      That is it!!!
      I have used eval before but never to do this.
      Sometimes it is harder to know how to ask the question than solving the problem.


      Thank you!
Re: interpret variable in a single quoted string
by ikegami (Patriarch) on Feb 08, 2011 at 21:44 UTC
    What you have there is a template. String::Interpolate is a module that processes such templates.