Generally whenever you want to execute a string or stored exppression like that as a statement, look for a function named eval or something comparable in the language. Programmers and language creators alike are lazy beasts: they often choose the same names for things, just look at how many languages have a print thingy ;-).
Do be mindful though, that when you do eval $str you are basically saying:
local $@;
{
put $str here as if I wrote it myself
and set $@ to contain any exception from perl.
}
So be warey of what you eval EXPR. You wouldn't want to execute eval(`rm -rf /var/db/mysql`) now would you? If you've got a lot of evals to do, you should also note that eval is slow.
__________________
My Journal
Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Last edited by TerryP; 16th February 2009 at 07:49 AM.
|