Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Perl libraries from PHP?

Tags:

php

perl

embed

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

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.

like image 349
freddiefujiwara Avatar asked Jun 23 '09 05:06

freddiefujiwara


People also ask

How do I know if a Perl library is installed?

You need to use instmodsh (interactive inventory for installed Perl modules) command to find out what modules already installed on my system. instmodsh command provides an interactive shell type interface to query details of locally installed Perl modules.


2 Answers

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:

<?php
    $perl = Perl::getInstance();
    $fh = $perl->new("IO::File", "<$file");
    while($fh->getline()) {
      # ...
    }
  ?>
like image 131
Nic Gibson Avatar answered Sep 23 '22 19:09

Nic Gibson


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.

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.

like image 34
Alexandr Ciornii Avatar answered Sep 23 '22 19:09

Alexandr Ciornii