in reply to Calling perl from java

The tool to call perl from java would be JNI(Java Native Interface). Which is a rather rich API provided by Sun. The definative reference/tutorial is Java Native Interface.

It can be tricky, but it can be done.

HOWEVER Given that you've implied that most of the need to call perl from java lies in Perl regexe's you should be aware that as of Java 1.4.1, Java includes a 'Pattern' class whose syntax closely parallels the Perl regex syntax with some differences(ref Pattern Docs)

It pains me to recommend this, but you would probably do well to examine how hard it would be to convert your existing perl regexes to Java Patterns if Java 1.4.1 is in use. If the patterns are relatively simple and you get the hang of Java patterns quickly enough, then you should probably go with converting your perl regexes to Java Patterns. Two days of kicking the tires on trying Java patterns to see if it would work would probably be time very well spent. If you're using regex syntaxes that are not well supported in Java patterns, look again at the JNI solution.

Also consider that if you move to a different platform, you're going to have to make sure that your JNI library works on that other platform as well.

Keep also in mind the people who follow you on this project. If you manage to keep it all Java, you've simplified their lives considerably. If you go the JNI route, they'll have to support Java, Perl, C/C++, Makefiles and JNI's own collection of issues.

Step back, and examine the pros and cons of both approaches very carefully.

Replies are listed 'Best First'.
Re: Re: Calling perl from java
by hardburn (Abbot) on Oct 15, 2003 at 20:25 UTC

    Given the highly OO nature of Java's new regex classes, they take far more lines of code to do the same thing as a Perl regex (not to mention that ?{ } isn't quite Perl Compatible :). Calling the Perl code without shelling-out will almost certainly be easier than dealing with Pattern.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    :(){ :|:&};:

    Note: All code is untested, unless otherwise stated

      As a longtime user and lover of Perl, I have to disagree with your assessment of Java's regex support. While it may be true that dealing with the Pattern object is a real pain, in the 1.4 JDKs they have also added to the String object .matches(), .split(), and other handy methods for dealing with regular expressions. Though you may still have your qualms about writing this type of code in Java (I for one abhor the hoops one has to jump through to get certain metacharacters properly quoted and escaped), it's not quite as bad as you make it seem. :-)

      Update: oooh, downvotes! Apparently the monks don't like posts that are anything less than completely critical of Java, even when they are correcting an error of misunderstanding, and point out something else bad about Java. Very nice. Sorry for the whining. 8^\