tel2 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
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.
Thanks.
Tel2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Executing a string as a Perl command
by ikegami (Patriarch) on May 10, 2011 at 01:34 UTC | |
|
Re: Executing a string as a Perl command
by tel2 (Pilgrim) on May 10, 2011 at 01:59 UTC | |
by johnpeterdinesh (Initiate) on May 10, 2011 at 09:22 UTC | |
by JavaFan (Canon) on May 10, 2011 at 11:14 UTC | |
by ww (Archbishop) on May 10, 2011 at 12:29 UTC | |
by ctilmes (Vicar) on May 16, 2011 at 10:48 UTC | |
by Anonymous Monk on May 16, 2011 at 11:01 UTC | |
| |
|
Re: Executing a string as a Perl command
by educated_foo (Vicar) on May 10, 2011 at 01:29 UTC |