Performance Zone is brought to you in partnership with:

A GNU/Linux g33k CLI+Web loving computer polyglot. Hemanth is a DZone MVB and is not an employee of DZone and has posted 16 posts at DZone. You can read more from them at their website. View Full User Profile

Perl in Node.js

09.13.2012
| 6826 views |
  • submit to reddit

Yes, Perl5 can be embedded in node.js! First of all, do a npm install perl. (P.S. node-perl requires a perl5 binary built with -fPIC and -Duseshrplib.) This is synchronous but useful embedded Perl5 for node.js. If you want to try any version of perl, you must check out perl-node.

#>git clone git://github.com/hideo55/node-perl.git
#>cd node-perl
#>node-waf configure
#>node-waf build
#>node-waf install

And then:

var Perl = require('perl').Perl();
var perl = new Perl();
 
perl.Run({
    opts : ["-Mfeature=say","-e","say 'Hello world'"]
}, function(out,err){
    console.log(out);
});
 
perl.Run({
    script : 'example.pl',
    args : ['foo', 'bar']
});

If you opted for Perl5:

var Perl = require('perl-simple').Perl;
var perl = new Perl();
var ret = perl.evaluate("reverse 'yoeman'");
console.log(ret); // => nameoy
 
var Perl = require('../index.js').Perl;
var perl = new Perl();
perl.use('LWP::UserAgent');
var ua = perl.getClass('LWP::UserAgent').new();
var res = ua.get('http://utf-8.jp/');
console.log(res.as_string());

Happy hacking!

Published at DZone with permission of Hemanth Madhavarao, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

André Pankraz replied on Fri, 2012/09/14 - 3:28am

Hi,

nice article but - why do I see this node.js stuff at Javalobby -and this article here is not an exception. Node.js tag seems to be a Javalobby indicator.
Is this intentional? node.js has nothing to do with Java.

Best regards,
André

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.