Over a million developers have joined DZone.

Perl in Node.js

· Performance Zone

Download Forrester’s “Vendor Landscape, Application Performance Management” report that examines the evolving role of APM as a key driver of customer satisfaction and business success, brought to you in partnership with BMC.

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!

See Forrester’s Report, “Vendor Landscape, Application Performance Management” to identify the right vendor to help IT deliver better service at a lower cost, brought to you in partnership with BMC.

Topics:

Published at DZone with permission of Hemanth HM, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}