|
Posted by Toby A Inkster on 01/18/08 12:48
Steve wrote:
> can you switch, in code, mid-stream to from one language to another?
In PHP? Yes, kinda, if you install the right modules. But only if by "one
language" you mean "PHP" and "another" you mean "Perl or Python".
An example of using Perl within PHP:
<?php
// Use embedded Perl
$perl = new Perl();
// Import function "md5_hex" from package "Digest::MD5"
$perl->eval('use Digest::MD5 qw(md5_hex);');
// Now we can call the function as a normal PHP object method.
echo $perl->md5_hex('Hello');
// prints "8b1a9953c4611296a827abf8c47804d7".
?>
It's slightly clunky in terms of syntax, but it's pretty cool and
occasionally useful if you want to be able to reuse a large piece of
already written Perl script in PHP. Perl functions can be made accessible
to PHP, and variables, arrays, hashes and objects passed back and forth
between the languages.
More info, downloads:
http://pecl.php.net/package/perl
http://pecl.php.net/package/python
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 18 days, 23:46.]
Ham vs Bacon vs Pork
http://tobyinkster.co.uk/blog/2008/01/17/pork-etc/
Navigation:
[Reply to this message]
|