monger has asked for the wisdom of the Perl Monks concerning the following question:

Greetings fellow monestary dwellers,

Today, I come with a question for the sages here. I have been given a project that has mixed perl and PHP scripts. I have a problem making one thing work now: a perl script passing some info to a PHP script. The way it was originally written was this:

`$MODULE::PROGS/variable_setup.sh $MODULE::PROGS/myscript.php 'data=$_ +[1]' > $file$_[1].$ext`;

When I pass this to PHP, it is agnostic of the variable passed to it. The variable "$_[1]" comes from the following:

open (IN,"$MODULE::INFO/data_file.txt"); foreach (<IN>) { split;

Everything on the perl side works fine. The perl debugger has been great. I've posted the same question to a PHP forum and had less than helpful responses. So, what wisdom do the monks have here? I am a bit stuck because the variable "$_[1]" will actually have a total of 10 elements as it is iterated through. So, can one assign an array to an environment vairable that PHP could then read? Assigning the data to an Apache variable? Other suggestions?

Thanks,

monger

Monger +++++++++++++++++++++++++ Munging Perl on the side

Edited by Chady -- escaped [ to prevent linking.

Replies are listed 'Best First'.
Re: Perl and PHP playing together
by bart (Canon) on Nov 29, 2004 at 19:15 UTC
    Serialize (freeze) the data into a string that PHP can read. See the PHP docs for serialize(), in particular the user comment by scott (at) hurring.com, and the little module he's written. You'll need unserialize() in PHP, to unfreeze, and use it.
Re: Perl and PHP playing together
by saberworks (Curate) on Nov 29, 2004 at 19:15 UTC
    If you pass 10 arguments separated by spaces, PHP can see them in $_SERVER['argv']. I briefly looked for a way to passed named arguments that would cause PHP to automatically parse them as an array, but I turned up empty. I seem to rememember being able to pass a URL-like string to PHP on the command line and have it parsed for me, but I can't find anything now so maybe my mind is playing tricks on me.

    Using PHP from the command line
Re: Perl and PHP playing together
by superfrink (Curate) on Nov 30, 2004 at 05:09 UTC
    I had to replace one PHP script with a Perl CGI script not too long ago. PHP changed the data it presents to it's scripts that describe the filename of uploaded files (via a form input). The old behaviour was to provide the whole path to the file. The new behaviour provides only the filename (ie no path). This happened in a dot release and I could not find mention of it in the changelog. This is one of the main reasons I stopped developing in PHP.

    Now I had a customer who had a Java program written to upload directories at a time via HTTP POST. His clients used it and logged in to his site which kept track of the uploads via PHP's session cookies. I had to fix it ASAP and I was not about to hack away at the PHP source or keep a custom patch to PHP for all future upgrades.

    I needed to get Perl to read PHP's session files to keep track of who was uploading what files. PHP::Session made this really easy. I did however have to change a variable in the code. (save_path in Session.pm).
Re: Perl and PHP playing together
by sweetblood (Prior) on Nov 29, 2004 at 19:04 UTC
    in your line:
    `$MODULE::PROGS/variable_setup.sh $MODULE::PROGS/myscript.php 'data=$_ +[1]' > $file$_[1].$ext`;
    you are single quoting the data=$_[1]. Perl will not interpolate $_[1] when wrapped in single quotes.It won't interpolate any variable inside single quotes for that matter.

    HTH

    Sweetblood

      Hello

      I don't think this statement is 100% correct. Perl won't interpolate between single quotes when assigning to a variable. However, if the single quotes are inside double-quotes or a set of backticks, it will interpolate. See the following.

      my $x = "this is the x variable"; my $y = 'single quote of $x'; my $z = "echo '$x'\n"; print $x, "\n"; print $y, "\n"; print $z; print `echo '$x'`; print `$z`; __DATA__ this is the x variable single quote of $x echo 'this is the x variable' this is the x variable this is the x variable
      note that the assignment to $z does interpolate $x, as does the backtick call to 'echo'

      -j

        I stand corrected. You are absolutely right.

        Thanks!

        Sweetblood