Perl5 to Java compiler - using a Perl module from Java

Perlito5 now supports calling Perl subroutines from Java.

For example, a Perl module was compiled to "Main.java", and it can be called using:

 class TestPerl {
    public static void main(String[] args) throws Exception {
        // initialize the Perl module - setup global variables
        // and create the subroutine entries
        Main.init();
        // locate the subroutine main::test
        // and call it with an argument list
        // that is: @res = main::test(123)
        PlObject[] res = Main.apply("main::test", new String[]{ "123" });
        // do something with the results
        for (PlObject s: res) {
            System.out.println("Java result: " + s.toString());
        }
    }
}

Leave a comment

About Flávio S. Glock

user-pic I blog about Perl.