note 19050 deleted from function.exec by vincent

From: Date: Wed, 10 Sep 2003 19:00:41 +0000
Subject: note 19050 deleted from function.exec by vincent
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55999@lists.php.net to get a copy of this message
Note Submitter: marat@provote.com ---- As we all know, there are often times more ways than one to skin a cat. The example above is universal in that the logic which supports it would work no matter how many arrays or hashes you needed to pass back to your PHP script, from the PERL script the PHP executed. However, if you were passing back strictly arrays, then you might want to try something a little more effecient, which would not require a 'foreach()' loop to produce the output on the PERL side. Passing back one or more arrays in PERL: <code> print "\"" . @array . "\" \"(array name)\" @(array name)" ; </code> This will produce a 'double-quote space double-quote' delimited string of array values. The first value in this string will be the number of members in the PERL array, while the second value is the name of the PERL array. This member number value becomes important on the PHP side, when we want to do a cursory consistency check on the PHP array. Grabbing output PERL arrays in PHP: <code> exec("path_to_perl_file", $array) ; while (list($name, $value) = each($array)) { $temparray = split('" "', $value) ; $perlarraylength = $temparray[0] ; $perlarrayname = $temparray[1] ; unset($temparray[0]) ; unset($temparray[1]) ; /* here is where the consistency check comes in */ if ($perlarraylength != sizeof($temparray)) { echo("corrupt perl to php array translation...") ;} else { ${$perlarrayname} = $temparray ;} unset($temparray) ;} </code> That's it..., quick and easy. Unfortunately, PERL hashes can't be handled in this fashion, seeing as how simply printing "%(hash name)" will yield the hex reference to the hash. Therefore PERL hashes must be passed back by printing each member through a loop... Needed to clarify, MARAT

« previous php.notes (#55999) next »