<?xml version="1.0" encoding="windows-1252"?>
<node id="903872" title="Executing a string as a Perl command" created="2011-05-09 21:25:33" updated="2011-05-09 21:25:33">
<type id="115">
perlquestion</type>
<author id="716732">
tel2</author>
<data>
<field name="doctext">
&lt;p&gt;Hi Monks,&lt;/p&gt;

&lt;p&gt;What is a simple way to execute a string as a Perl command, in a Perl script?&lt;/p&gt;

&lt;p&gt;For example, let's say I have a scalar assignment like this:&lt;/p&gt;
&lt;code&gt;$cmd = '$var1 = 5;';&lt;/code&gt;
&lt;p&gt;If I want to execute $cmd, ending up with $var1 containing 5, what's an easy way to do it, (without parsing the string, picking out the variable &amp; value, and making the assignment with an indirect reference). &amp;nbsp;I've looked at 'eval', and other posts here, but can't find anything appropriate yet.&lt;/p&gt;

&lt;p&gt;Thanks.&lt;br&gt;
Tel2&lt;/p&gt;</field>
</data>
</node>
