2

I am trying to copy the contents of an array generated from a Perl script into an array on a PHP page. Is this possible?

Current code in PHP file:

$campaigns_array[][] = shell_exec('recent_campaigns.pl $companyID');

recent_campaigns.pl runs some mySQL queries and creates an array from it. I don't know how to get that array from the Perl script.

Thanks in advance.

2 Answers 2

5

The easiest way is to output the result as json and then use json_decode to read it back in PHP.

Sign up to request clarification or add additional context in comments.

Comments

0

The reply is either:

  1. parse the output and build the array from it, or
  2. modify the script so as to build a php string that you can eval, or
  3. dispense with the stupid script altogether and run the queries within php (after all, mysql connectivity is supposed to be one of PHP's strong suites)

Being more precise is hard, as you are not providing an output sample and are not saying if you have control on the script output, etc.

4 Comments

I'd love to just do it in PHP, but am required to use Perl by my employers. I do have control over the output, but it literally just reads a mySQL query into an array, which works fine. I just don't know how you pass that array into PHP.
then have perl print a PHP array literal (php.net/manual/en/function.array.php) then eval("\$campaigns_array = \"shell_exec('recent_campaigns.pl $companyID')\";");
JSON is much better...both PHP and Perl can "understand" it, so its much easier than mangling together an PHP array literal.
"mysql is supposed to be one of PHP's strong suites" emphasis on the "supposed to" :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.