简体   繁体   中英

Run perl online

I want to run a Perl script online, but I don't know how.
In PHP you need to start with <?php , so do you have to start with something like that in Perl?
And does Apache automatically recognize Perl? Or do I have to upload Perl and let it point to it using #!/path/to/perl ? Can I use print() to display HTML?

In PHP you need to start with <?php , so do you have to start with something like that in Perl?

There are frameworks (such as Mason) which work like that, but it is more typical to have a standard Perl program which outputs the page.

And does Apache automatically recognize Perl?

Apache doesn't automatically recognise any kind of server side programming.

Or do I have to upload Perl and let it point to it using #!/path/to/perl?

You would need to have Perl installed on the server. You would generally start a script that way (but not necessarily, eg if you were using mod_perl), but would have to configure the server to recognise it as an executable and run it (just as you have to configure the server to recognise files ending with .php as scripts to run with PHP).

Can I use print() to display HTML?

Yes.

You should probably start by looking at the question Web Programming For The Non-Web Programmer (in Perl) .

Must you use Apache? If not here is an alternative to consider.

I have found that the built-in servers and templating engine in the Mojolicious framework work very naturally for inline Perl within HTML. The tags are of the form <%== but work the same way. Also it has good documentation and examples to get you going.

Edit: It seems that there are ways to use Apache with Mojolicious too, see http://search.cpan.org/perldoc?Mojolicious::Guides::Cookbook , though the built-in servers have worked well for me, with FAR less (ie no) configuration.

Apache HTTP doesn't automatically understand Perl or PHP for that matter. For PHP to work, you have to have the Apache httpd module called something like mod_php.so or libphp5.so installed. However, since many websites use PHP in this manner, this Apache httpd module is normally installed.

Just as you need mod_php in order to use PHP in Apache's httpd web server, you need to do is make sure your web server is using mod_perl if you want to use Perl in a similar manner.

You'll need to build and install mod_perl which can be tricky -- especially if you don't control the machine the server is on.

The other way to use Perl is to use what's known as CGI-Perl . This is much easier to setup, but it is also much more dangerous since it can lead to someone being able to run unauthorized programs on your Apache httpd server.

In this case, you need to set up a CGI-BIN directory, and configure Apache httpd . This is fairly simple. Once you do that, you put all of your Perl scripts into the _CGI_BIN_ directory. In this case, your Perl scripts will have to handle all of the communication between your web server and the web client and handle all displays. Fortunately, it's not too difficult in perl since Perl gives you the basic modules to do this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM