简体   繁体   English

在线运行perl

[英]Run perl online

I want to run a Perl script online, but I don't know how. 我想在线运行Perl脚本,但是我不知道如何。
In PHP you need to start with <?php , so do you have to start with something like that in Perl? 在PHP中,您需要以<?php开头,那么您是否必须在Perl中以类似的内容开头?
And does Apache automatically recognize Perl? Apache是​​否会自动识别Perl? Or do I have to upload Perl and let it point to it using #!/path/to/perl ? 还是我必须上传Perl并使用#!/path/to/perl使其指向它? Can I use print() to display HTML? 我可以使用print()显示HTML吗?

In PHP you need to start with <?php , so do you have to start with something like that in Perl? 在PHP中,您需要以<?php开头,那么您是否必须在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. 有一些框架(例如Mason)可以像这样工作,但是更典型的是有一个标准的Perl程序来输出页面。

And does Apache automatically recognize Perl? Apache是​​否会自动识别Perl?

Apache doesn't automatically recognise any kind of server side programming. Apache不会自动识别任何类型的服务器端编程。

Or do I have to upload Perl and let it point to it using #!/path/to/perl? 还是我必须上传Perl并使用#!/ path / to / perl使其指向它?

You would need to have Perl installed on the server. 您将需要在服务器上安装Perl。 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). 通常,您可以以这种方式启动脚本(但不一定要启动,例如,如果您使用的是mod_perl),但是必须将服务器配置为将其识别为可执行文件并运行它(就像您必须配置服务器以识别文件结尾一样)使用.php作为要与PHP一起运行的脚本)。

Can I use print() to display HTML? 我可以使用print()显示HTML吗?

Yes. 是。

You should probably start by looking at the question Web Programming For The Non-Web Programmer (in Perl) . 您可能应该首先看一下非Web程序员的Web编程问题(在Perl中)

Must you use Apache? 您必须使用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. 我发现Mojolicious框架中的内置服务器和模板引擎对于HTML内联Perl非常自然地工作。 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. 编辑:似乎也有将Mojolicious与Apache一起使用的方法,请参阅http://search.cpan.org/perldoc?Mojolicious::Guides::Cookbook ,尽管内置服务器对我来说效果很好,与FAR更少(即没有)配置。

Apache HTTP doesn't automatically understand Perl or PHP for that matter. Apache HTTP不会自动了解Perl或PHP。 For PHP to work, you have to have the Apache httpd module called something like mod_php.so or libphp5.so installed. 为了使PHP能够正常工作,必须安装名为mod_php.solibphp5.so类的Apache httpd模块。 However, since many websites use PHP in this manner, this Apache httpd module is normally installed. 但是,由于许多网站都以这种方式使用PHP,因此通常会安装此Apache httpd模块。

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. 正如需要mod_php以便在Apache的httpd Web服务器中使用PHP一样,如果您想以类似方式使用Perl,则需要确保Web服务器正在使用mod_perl

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. 您将需要构建和安装mod_perl ,这可能很棘手-特别是如果您不控制服务器所在的计算机。

The other way to use Perl is to use what's known as CGI-Perl . 使用Perl的另一种方法是使用所谓的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. 这很容易设置,但是也更危险,因为它可能导致某人能够在您的Apache httpd服务器上运行未经授权的程序。

In this case, you need to set up a CGI-BIN directory, and configure Apache httpd . 在这种情况下,您需要设置一个CGI-BIN目录,并配置Apache httpd This is fairly simple. 这很简单。 Once you do that, you put all of your Perl scripts into the _CGI_BIN_ directory. 完成后,将所有Perl脚本放入_CGI_BIN_目录。 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. 在这种情况下,您的Perl脚本将必须处理Web服务器和Web客户端之间的所有通信并处理所有显示。 Fortunately, it's not too difficult in perl since Perl gives you the basic modules to do this. 幸运的是,在Perl中并不太困难,因为Perl为您提供了执行此操作的基本模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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