我如何使用PHP的Perl库?

时间:2021-01-25 02:34:52

I want to use Perl libraries from a PHP application. I have heard that it is possible.

我想从PHP应用程序中使用Perl库。我听说有可能。

I have considered the possibility of re-writing the libraries in PHP, but I do not think that is a good idea because it is difficult.

我已经考虑过用PHP重写库的可能性,但我认为这不是一个好主意,因为它很难。

2 个解决方案

#1


You could also use PHP::Interpreter from CPAN. This allows you to embed a PHP interpreter in Perl and also, more usefully for you, to create a Perl object in PHP:

您也可以使用CPAN中的PHP :: Interpreter。这允许您在Perl中嵌入PHP解释器,并且对您来说更有用的是在PHP中创建Perl对象:

<?php
    $perl = Perl::getInstance();
    $fh = $perl->new("IO::File", "<$file");
    while($fh->getline()) {
      # ...
    }
  ?>

#2


You can use Inline::PHP CPAN module from Perl to integrate PHP code (just use library and call you your PHP code). Or you can use perl PECL extension to call Perl from PHP.

您可以使用Perl的Inline :: PHP CPAN模块来集成PHP代码(只需使用库并调用您的PHP代码)。或者您可以使用perl PECL扩展从PHP调用Perl。

In future you will be able to use Parrot virtual machine to use libraries from any supported language. Parrot supports this, but Perl 5 and PHP support in Parrot is weak.

将来,您将能够使用Parrot虚拟机来使用任何支持语言的库。 Parrot支持这一点,但Parrot中的Perl 5和PHP支持很弱。

#1


You could also use PHP::Interpreter from CPAN. This allows you to embed a PHP interpreter in Perl and also, more usefully for you, to create a Perl object in PHP:

您也可以使用CPAN中的PHP :: Interpreter。这允许您在Perl中嵌入PHP解释器,并且对您来说更有用的是在PHP中创建Perl对象:

<?php
    $perl = Perl::getInstance();
    $fh = $perl->new("IO::File", "<$file");
    while($fh->getline()) {
      # ...
    }
  ?>

#2


You can use Inline::PHP CPAN module from Perl to integrate PHP code (just use library and call you your PHP code). Or you can use perl PECL extension to call Perl from PHP.

您可以使用Perl的Inline :: PHP CPAN模块来集成PHP代码(只需使用库并调用您的PHP代码)。或者您可以使用perl PECL扩展从PHP调用Perl。

In future you will be able to use Parrot virtual machine to use libraries from any supported language. Parrot supports this, but Perl 5 and PHP support in Parrot is weak.

将来,您将能够使用Parrot虚拟机来使用任何支持语言的库。 Parrot支持这一点,但Parrot中的Perl 5和PHP支持很弱。