title: How can I eval environment variables in Perl?
body: <p>I would like to evaluate an environment variable and set the result to a variable:</p>
  
  <pre><code>$x=eval($ENV{EDITOR});
  print $x;
  </code></pre>
  
  <p>outputs:</p>
  
  <pre><code>/bin/vi
  </code></pre>
  
  <p>works fine.</p>
  
  <p>If I set an environment variable QUOTE to \' and try the same thing:</p>
  
  <pre><code>$x=eval($ENV{QUOTE});
  print $x;
  </code></pre>
  
  <p>outputs:</p>
  
  <p>(nothing)</p>
  
  <pre><code>$@ set to: "Can't find a string terminator anywhere before ..."
  </code></pre>
  
  <p>I do not wish to simply set <code>$x=$ENV{QUOTE};</code> as the eval is also used to call a script and return its last value (very handy), so I would like to stick with the eval();  Note that all of the Environment variables eval'ed in this manner are set by me in a different place so I am not concerned with malicious access to the environment variables eval-ed in this way.</p>
  
  <p>Suggestions?</p>