Andi Gutmans wrote: > Hey, > > As some of you might have noticed, Dmitry worked on a Perl extension which > allows PHP to run Perl scripts as well as instantiate Perl objects in PHP > and use them.
i have done something similiar in the pass but with a different approach. i have written a PHP extension where it's capable of running any arbitary Perl code and return the result back to PHP > The main problem with the extension is the fact that Perl functions behave > differently according to their context (scalar/array) which doesn't exist > in PHP. We thought of all sorts of ways to solve this problem but aren't > sure what the best approach would be. > The current implementation uses scalar as default, and if you want an > array, you can use perl_wantarray() and the next method call would return > an array (the one after that would return scalar): > > Example: > > $x = new Perl("Test"); > $y = $x->f(); // scalar context; > perl_wantarray(); > $y = $x->f(); // array context; > $y = $x->f(); // scalar context; > in my extension, i have handled this situation base on the context within the Perl code, not in PHP. everything is passed back to PHP as reference except for scalar. the reference is then dereferenced base on the "type" they are point to so for example: <?php dl("perl.so"); $k = p2p_eval("%k = 1..10; \%k"); print_r($k) ?> prints: Array ( [1] => 2 [3] => 4 [7] => 8 [9] => 10 [5] => 6 ) which returns a hash to $k but: $k = p2p_eval("@k = 1..10; [EMAIL PROTECTED]"); print_r($k); prints: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 ) which returns an array back to $k because the last expression of the Perl code evaluates to an array reference. scalars are returned by value: $k = p2p_eval("'x1234y' =~ /(\d+)/; $1"); print_r($k); prints: 1234 this way, i don't have to concern about what context the PHP code is being used as long as the Perl code returns the right thing in the right context, my extension will handle the data type correctly. just something to share... david -- s$s*$+/<tgmecJ"ntgR"tgjvqpC"vuwL$;$;=qq$ \x24\x5f\x3d\x72\x65\x76\x65\x72\x73\x65 \x24\x5f\x3b\x73\x2f\x2e\x2f\x63\x68\x72 \x28\x6f\x72\x64\x28\x24\x26\x29\x2d\x32 \x29\x2f\x67\x65\x3b\x70\x72\x69\x6e\x74 \x22\x24\x5f\x5c\x6e\x22\x3b\x3b$;eval$; -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php