473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to call perl function from PHP

sam
I have a function writen in Perl that takes a name-value list (array) as
argument
and returns a name-value list (array).

My question is:
How to call this function from PHP and get the returned name-value list in
PHP variable?

Thanks.
Jul 16 '05 #1
1 19313
sam wrote:
I have a function writen in Perl that takes a name-value list (array) as
argument
and returns a name-value list (array).

My question is:
How to call this function from PHP and get the returned name-value list in
PHP variable?

Thanks.


Here begins a ramble.

One way is to make a Perl script containing your function which accepts
a variable on the command line (%ARG), so that, if called on the command
line as follows:

perl script.pl your_variable

it will print the data to standard out after running it through the Perl
subroutine.

You can call the Perl script using PHP's passthru() function and get the
output of the script into a PHP variable:

$result=passthru("perl script.pl your_variable");

Now the difficulty lies in passing the key/value array on the command
line. PHP has a serialize() and unserialize() function, which converts
data structures to and from a string. Perl has no such thing but this
Perl module will do the trick:

http://hurring.com/code/perl/serialize/

So PHP serializes the data, calls the Perl script with the serialized
data on the command line, Perl unserializes the data, runs it through
the function, serializes the result, prints it to the standard out, PHP
receives the serilazed data, unserializes it and voila.

You'll need to consider security to make sure nothing dangerous can get
executed by the passthru() function. Take a look at escapeshellarg() and
escapeshellcmd().

Additionally, a command line has a maximum length (I'm unsure what it is
off the top of my head). If this is a problem, you could pass the data
in a file which can be shared between PHP and Perl.

Alternatively, rewrite your Perl function in PHP.

Does this help?
--
MeerKat

Jul 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Randell D. | last post by:
Folks, I feel like pulling my hair out - I tried unsuccessfully over the past few days to install ImagMagick but because of version conflicts and missing libraries I had to give up. I originally...
1
by: Mark Ohlund | last post by:
I'm trying to use the PDL modules to perform a Vector Space search as shown in: http://www.perl.com/pub/a/2003/02/19/engine.html I'm running FreeBSD 4.9 w/ Perl 5.6.1 and 2.4.1 of PDL. The...
7
by: AznCollegeGuy | last post by:
Hello, Im trying to invoke a simple perl script with in my visual c++ gui program to with c++'s system call feature: when i call: system("dir"); it works
6
by: Xing Xu | last post by:
Hi guiders, sorry , since I don't know which group suit for this question,I just post this question at these group. As we know , we can get the run-time call graph by some proved tools . now...
35
by: hasho | last post by:
Why is "call by address" faster than "call by value"?
5
by: Ham | last post by:
Hi I am looking for a function call tree program to map the function calls of my project. I however do not want to compile my project. All the programs I have found for this require you to...
2
by: Mark Cummings | last post by:
I am migrating an Oracle 9i to Oracle 10g database, and Perl 5.0.4 to Perl 5.8.7 in Sun Solaris environment. Using Perl 5.8.7, the following legacy code segment is returning a '-1' return code on...
6
by: tuxy94 | last post by:
I do not understand why the variable @data_file keeps the data from the previous call. My goal is to use this in order to clean a file from specific lines I do not desire, I do so, but if I run...
5
by: cnsabar | last post by:
Hi., I want to call some function when the user force to terminate the perl program. For example., I write a program to create a file when the program starts... Also I need to delete a file...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.