Using Perl Code in PHP

0
Your rating: None

PHP perl extension is available to allow the usage of perl code in PHP.

The perl extension is used to load and execute perl files, evaluate perl code, access perl variables, call perl functions, instantiate perl objects, access properties of perl objects, call methods of perl objects.

PHP's perl extension is available from the PECL web site at http://pecl.php.net/package/perl. The latest development version can be obtained with the following CVS command:

$ cvs -d :pserver:cvs.php.net:/repository co pecl/perl

If you have a full perl installation, the extension will work with it. If you don't have perl on board, you can still communicate with the perl interpreter through PHP by putting a copy of perl58.so or perl58.dll somewhere PHP can find it (in the PHP directory or in your system path).

To access the perl interpreter from PHP, you must first create an instance of the Perl class.

$perl = new Perl();

External perl files can be loaded using the Perl::require() method. An example is:

<?php

print "Hello from PHP! ";
$perl = new Perl();
$perl->require("kiranhota.pl");
print "Bye! ";

?>

The system() function will start the interpreter each time it's called, whereas $perl->eval() uses the embedded interpreter in the same address space and doesn't need to create a new process. An example is:

<?php

print "Hello from PHP! ";
$perl = new Perl();
$perl->eval('print "Hello from perl! "');
print "Bye! ";

?>

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Cumulus Tag Cloud

Kiran Says

SEO Architect,SEO Specialist reflect my values.

By enduring black hat methods the SEO industry is setting itself up for washout and sleepwalking into oblivion.

Jobs in India