Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Is there any module to use perl Api's with return values Hash and array in my java code

by srins (Sexton)
on Jun 28, 2006 at 09:41 UTC ( #557972=perlquestion: print w/replies, xml ) Need Help??
srins has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
Can i use perl api's in java.
We are using some api written in perl .The return value for those api may be hash or arrays.Can i use these return values in java code.We are trying to build jsp pages and servelets which may use some of these perl api's.
Is there any module for getting perl api's return values and use that return values in my java code.
Thanks,
srini.
  • Comment on Is there any module to use perl Api's with return values Hash and array in my java code

Replies are listed 'Best First'.
Re: Is there any module to use perl Api's with return values Hash and array in my java code
by Corion (Pope) on Jun 28, 2006 at 09:50 UTC

    If I understand correctly what you want, I see two possible ways, both of which are cool if they immediately work for you and very, very ugly if they don't:

    • Use Inline::Java. This gives you a nice and convenient bridge between Perl and Java and allows you to pass data between them. I don't know if it can magically convert complex datastructures, but that should be a minor problem as long as all structure you have is arrays and hashes.
    • Use a webservice to talk from Java with Perl. This means setting up your Perl code to be a SOAP server and then accessing it from Java via some webservice API.

    If neither of the two ways works for you, I recommend communicating through a database or the filesystem - both languages have enough facilities to conveniently access the shared resource. Of course, then you will have to write your own code to serialize and deserialize the data, but maybe you can hack a storage for Java hibernate together which nicely deserializes in Perl.

Re: Is there any module to use perl Api's with return values Hash and array in my java code
by shmem (Chancellor) on Jun 28, 2006 at 11:36 UTC
    For the one way round, see JNI (a Perl encapsulation of the Java Native Interface) and PBJ::JNI (full access to and from Java virtual machine from Perl). As for the other way round - calling perl from within Java - you might have a look at Jakarta ORO, they've done something with perl regexes. I don't know how they implemented it, wether they us perllib etc., since I'm no Java programmer. But maybe it's a starting point.

    --shmem

    _($_=" "x(1<<5)."?\n".q/)Oo.  G\        /
                                  /\_/(q    /
    ----------------------------  \__(m.====.(_("always off the crowd"))."
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      Jakarta ORO just provides perl compatible regular expressions, it doesn't actually provide any interface to Perl. And for what it's worth, I have found the claim of compatibility to be a little misleading. I was unable to port some of my Perl regular expressions to ORO and had to resort to an ugly set of if/elses. That was before JDK 1.4 was available, I can't recall if I went back and tried to implement the same regular expressions with the native JDK 1.4 support.

      I've solved a problem similar to the OP's with a Perl web service called by a Java client, but the performance of SOAP::Lite web services was pretty poor.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://557972]
Approved by Corion
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2018-02-22 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (288 votes). Check out past polls.

    Notices?