java怎么调perl,如何从Java调用Perl?

I have a Perl module that I would like to use from Java. Is there a way to call this code using either ActiveState Perl on Windows or the generic Perl that comes with Linux? I have found references to JPL but it doesn’t appear to be maintained anymore.

解决方案

Inline-Java is the usual library to call java from Perl, and this post propose a org.perl.java module which should allow calling Perl from Java, as asked.

However, because of the unpredictability of the JNI implementations for different

JVMs it is difficult to say what combinations of JVM and Perl will work. Typically, what is required is Perl with MULTIPLICITY, and threads compiled in. That means he uses a custom built Perl.

Otherwise, org.perl.inline.java.InlinePerlCaller object. Here is a example of a typical use:

use Inline Java => <

import java.util.* ;

import org.perl.inline.java.* ;

class Pod_regexp extends InlineJavaPerlCaller {

public Pod_regexp() throws InlineJavaException {

}

public boolean match(String target, String pattern)

throws InlineJavaException {

try {

String m = (String)CallPerlSub("main::regexp",

new Object [] {target, pattern}) ;

if (m.equals("1")){

return true ;

}

}

catch (InlineJavaPerlException pe){

// $@ is in pe.GetObject()

}

return false ;

}

}

END

my $re = new Pod_regexp() ;

my $match = $re->match("Inline::Java", "^Inline") ;

print($match . "n") ; # prints 1

sub regexp {

my $target = shift ;

my $pattern = shift ;

return ($target =~ /$pattern/) ;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值