Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Executing code block in memory

by morissette (Novice)
on Aug 08, 2012 at 21:39 UTC ( [id://986368]=note: print w/replies, xml ) Need Help??


in reply to Re: Executing code block in memory
in thread Executing code block in memory

I tried this but I dont think its everything you were talking about:
#!/usr/bin/perl -w use URI::Escape; use HTML::Entities; use CGI qw/:standard/; print "Content-type: text/html\n\n"; my $file; if(param('test')){ my $code = param('test'); $code = uri_unescape($code); $code = encode_entities($code); open STDERR, '>&STDOUT'; open my $fh, '>', \$file; print $fh $code; close $fh; open my $pipe, '-|', "perl -w $file"; close $pipe; close STDERR; }
The output I get with this is:
sh: -c: line 0: syntax error near unexpected token `;;' sh: -c: line 0: `perl -w print "hi";'
This is what is passed to the script:
print "hi"; print "hello world\n";

Replies are listed 'Best First'.
Re^3: Executing code block in memory
by kennethk (Abbot) on Aug 08, 2012 at 22:18 UTC
    A modified version of your sample that does what I mean:
    #!/usr/bin/perl -w use strict; use URI::Escape; use HTML::Entities; use CGI qw/:standard/; use CGI::Carp 'fatalsToBrowser'; print header; my $file; if(param('test')){ my $code = param('test'); $code = uri_unescape($code); $code = encode_entities($code); open STDERR, '>&STDOUT'; eval $code; print $@ if $@; }

    No need to create external, temporary files. There are some potential messy issues in there, but this is good enough for rough cut.


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://986368]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 15:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found