Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

The task is to execute functions stored in a database, preferably xml. For example a function containing system.out.println("a"); is stored in a file code.xml and has been extracted as a string, how can a program be made so as to execute said code ?

Winning criteria : Efficient and fast code (as the executed functions may themseleves be long too)

share|improve this question
    
How are you going to check the fastest code? –  ProgramFOX Jan 11 at 16:37
    
Sorry if it seems amateur, but I was hoping for execution time of codes ! –  rijul gupta Jan 11 at 16:40
    
And how are you going to check the execution time? –  ProgramFOX Jan 11 at 16:49
    
I am used to using netbeans, it has a feature of showing execution time. I suppose that should do the job. –  rijul gupta Jan 11 at 16:56
    
But what if someone posts a code in a language that Netbeans doesn't support? –  ProgramFOX Jan 11 at 17:03
show 2 more comments

closed as unclear what you're asking by ProgramFOX, Jan Dvorak, Peter Taylor, hildred, Quincunx Jan 12 at 0:59

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers

Polyglot (Ruby, JavaScript, Python, PHP, Perl)

Assuming code is stored in the $c variable:

eval($c);
share|improve this answer
    
Looks like I posted it 30s late :P –  Vereos Jan 11 at 16:40
    
I have a small query, all over the Internet eval is ridiculed as writing such codes brings up problems of security and code repairs, is this really a reliable way ? –  rijul gupta Jan 11 at 16:44
4  
You didn't ask for reliable, you asked for efficient and fast. –  Paul R Jan 11 at 17:08
    
I know I did not, it was more like an addendum to the existing query. –  rijul gupta Jan 11 at 18:08
add comment

PHP 5

$xml = simplexml_load_file("code.xml");
$myFun = (string) $xml->Function['value']; //Example path as no specs were given.
eval $myFun;
share|improve this answer
add comment

TI-BASIC

Executed from a TI-84 calculator*

Assuming XML code in the database X:

:expr(X

*YOU CAN'T USE NETBEANS HERE

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.