tags:

views:

161

answers:

2

Is it possible to save some Perl code in a database then retrieve it using a select statement and then execute that Perl code? I have tried using eval, but that doesn't seem to work.

Here is what I'm trying right now and it doesn't seem to work:

my $temp = $qryResults[0];
print $temp."\n";
eval{"$temp"};

the output is $con->Disconnect();exit;

+1  A: 

I figured it out; if I remove the curly brackets then it works.

TheGNUGuy
Good luck, you're going to need it.
Ether
+6  A: 

You just need:

eval $temp;

The reason your version didn't work is due to the block form of eval evaluating it as if you had written a simple string:

eval{"perl code here"}

is like writing this line of perl:

"perl code here"

It isn't code, its a string. Block form evals what is inside the block. If a string is inside the block, its just a string, not a script. String form evals what is inside the string.

mrjoltcola
Yes. Even though they're both called `eval`, `eval { BLOCK }` and `eval "STRING"` are **not** interchangeable.
Dave Sherohman
Many tearful programming sessions began with "hey, if I just use eval...". My advice: DON'T.
Ether