如何在Windows上通过XAMPP运行Perl文件?

Web*_*ots 8 apache xampp perl wamp

我是Perl语言的新手,我尝试像运行PHP文件一样运行它,方法是将文件放在htdocs中,然后通过localhost访问它们.

下面是我创建的Perl文件,但无法在localhost上运行:

----- hello.pl ---------------

   #!/usr/bin/perl
   print "Hello World.\n";
Run Code Online (Sandbox Code Playgroud)

Din*_*tra 15

  1. 安装xampp.在安装过程中,请确保已检查要安装的perl.
  2. 我假设你已经在c:/ xampp目录中安装了xampp.
  3. 现在转到c:/ xampp/htdocs目录.在htdocs目录里面创建一个perl目录.现在在perl目录中,创建一个名为hello.cgi的文件.
  4. 在hello.cgi中编写以下代码片段.

你好世界节目:

#!C:\xampp\perl\bin\perl.exe
# The above line is perl execution path in xampp
# The below line tells the browser, that this script will send html content.
# If you miss this line then it will show "malformed header from script" error.
print "Content-type: text/html\n\n";
print "Hello world."
Run Code Online (Sandbox Code Playgroud)

现在从xampp控制面板启动apache.在浏览器的url中,输入localhost/perl/hello.cgi.


Tim*_*Tim 4

如果您的 PHP 安装有 Perl 模块,您可以直接从 PHP 评估 Perl 代码。

<?php
    print "Hello from PHP!";
    $perl = new Perl();
    $perl->require("test1.pl");
    print "Bye!";
?>
Run Code Online (Sandbox Code Playgroud)

  • 否则你可以设置 apache 通过 CGI 使用 perl (3认同)