Page 1 of 1

Running perl module from PHP <--- HOWTO

Posted: Sat Sep 13, 2003 2:28 pm
by rustyambrose
I would like to run a perl module from a php page, using variables from the php page in the module, then needing a set variable from the module used back in the php. What is the best way to do this?

Posted: Sat Sep 13, 2003 3:14 pm
by scorphus
I don't know much of Perl but I belive you can do something like this:

cgi_module.pl:

Code: Select all

#!/usr/bin/perl

# treat arguments here...

# ...

# the print the significant data to PHP
print "This data was returned from the Perl script";
yourpage.php:

Code: Select all

<?php
$php_var = 'something';
$var_set_from_perl = `./cgi_module.pl $php_var`;// $php_var is the argument to the *executable* Perl script
echo 'The Perl script returned: ' . $var_set_from_perl;
?>
output:

Code: Select all

The Perl script returned: This data was returned from the Perl script
Take a look to the Execution Operators.

Hope it helps!

Regards,
Scorphus.

Posted: Sat Sep 13, 2003 5:34 pm
by m3rajk
if you're not using cgi modules, make the perl script, and call it via the exec function, just set it to take variables via the command line that you feed it via the exec call

Posted: Sun Sep 14, 2003 5:27 pm
by rustyambrose
Thanks scorphus, that's what I needed for the project I'm on. But I can see I might need to look into m3rajk's idea to see if the variables will be sent over from the perl, vs setting one variable equal to everyting.