M
M
Mithgol2011-02-17 12:13:59
Perl
Mithgol, 2011-02-17 12:13:59

How is it appropriate for a Perl script called from some program to interact with another (called by it) program (or with a script in general)?

There is a popular cross-platform C program (this program is HPT , if you're interested; but that's not essential), which long ago included the ability to call external Perl scripts ( in that unofficial build on Google Sites, for example).
A typical Perl routine receives a set of preset variables from this program and returns a set of parameters. A good example is a filter:

sub filter
{
# predefined variables:
# $fromname, $fromaddr, $toname,
# $toaddr (for netmail),
# $area (for echomail),
# $subject, $text, $pktfrom, $date, $attr
# $secure (defined if message from secure link)
# return "" or reason for moving to badArea
# set $kill for kill the message (not move to badarea)
# set $change to update $text, $subject, $fromaddr, $toaddr,
#     $fromname, $toname, $attr, $date
  return "";
}

It became interesting to me (and this is exactly my question) whether it is possible to use this functionality in order to use the pearl function as a means of calling another program - and then, perhaps, through it, a script in another language (say, in PHP or in Javascript ) if that other program happens to be a script interpreter.
I must admit right away that I myself do not know Pearl very well, I do not really like it and have not programmed on it for a long time. The question is addressed to those who know him well enough. Perl has a lot of ways to call external programs and pass data to (and then receive data from) them; IPC::Open2 comes to mind first. Would any of the methods work for the above purpose? What could be the difficulties?
It seems that on all platforms, the child process inherits environment variables from the parent, so variables from Perl to non-Perl can be passed through the environment ( %ENV hash , or is there something better? ...). True, on some platforms there are restrictions on the size of one environment variable and / or the entire environment as a whole; In order not to run into this gag, you can apply the largest value (the value of the $text variable ) to the input of the called program.
How to return multiple values ​​from the called program ( $kill and $changein the above example) along with the main value (which is easy to read from the standard output of the called program)? Difficulty, difficulty! Environment variables from the child process are not passed to the parent, and only dirty hacks come to my mind (for example, using an intermediate file with a random name), which should slow down a lot. Or submit a serialized object to the output of the called program?
I look forward to your ideas and practical advice. Links to blog posts and manuals in which someone has already solved this problem for themselves would be quite useful.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Renat Ibragimov, 2011-03-02
@MpaK999

if from C, then I would look towards perlxs
as options for pipes (IO:: Pipe) and, for example, XML:: RPC

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question