|laziness, impatience, and hubris|
Executing a string as a Perl commandby tel2 (Monk)
|on May 10, 2011 at 01:25 UTC||Need Help??|
tel2 has asked for the
wisdom of the Perl Monks concerning the following question:
What is a simple way to execute a string as a Perl command, in a Perl script?
For example, let's say I have a scalar assignment like this:$cmd = '$var1 = 5;';
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 & value, and making the assignment with an indirect reference). I've looked at 'eval', and other posts here, but can't find anything appropriate yet.