473,659 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 19343
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=passthr u("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
68819
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 choose ImageMagick because I've heard so much about it. I then decided to go with the inbuilt GD tools since I'm using PHP 4.3.3 that I compiled with --with-gd. I can use some of the image functions in PHP so why is this one undefined? What...
1
3208
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 source code for the search is: http://www.perl.com/2003/02/19/examples/VectorSpace.pm I'm calling this with the following code:
7
4430
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
16438
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 I have a problem about the extract call graph from statice C source code , not from binary. I have try to use cscope and write some perl script for it .
35
10771
by: hasho | last post by:
Why is "call by address" faster than "call by value"?
5
6686
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 compile the project which may span over 20 files or so. I would prefer the output probably to be in text so I can create a perl script to analyse the results.
2
4067
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 the system call to execute the 'mv' command. Note that the mv request is across directories. sub move_inproc { print "sub move_inproc\n"; `mv $histhome/dat/inbound/$filename $histhome/dat/inproc/$filename`; if ($? !=0) {
6
1550
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 this method twice, it will append the data of the current call after the data from the previous call. Is there a way I can reset the @data_file each time the function is called or is there something I can do to help? Here is the code for the...
5
2746
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 when the user force to terminate the process i.e Calling some function when the user hitting Ctrl+C in perl command prompt..
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.