Sachin_dada has asked for the wisdom of the Perl Monks concerning the following question:

In Perl, i want to read the array that is actually passed from java. Could someone please tell me, how to send the arrays from java & read the array contents in Perl.

Replies are listed 'Best First'.
Re: Java to perl
by Anonymous Monk on Oct 18, 2010 at 06:52 UTC
    serialize the array (say using YAML), communicate with perl process (STDIN/ARGV/file.yml), then in perl use YAML::Load to get at it.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Java to perl
by snape (Pilgrim) on Oct 18, 2010 at 08:06 UTC

    Passing of an array from Java into a Perl is generally done in the form of a scalar reference. There are many other ways but I would prefer scalar reference. Also you need to use the GetIntArrayElements -- which is a jni function which is used to convert the scalar into an array of integers.

    For example:

    public class arrayforPerl { perl void max( int[] data ) {{ # Get the array elements # my @arrPerl = GetIntArrayElements( $data ); my @arrMax = sort {$a <=> $b} @arrPerl; print "Max: $arrMax[$#arrMax]\n"; }} ## double braces are for the perl code void maxProg() { int[] data = {101, 99, 42, 666, 23}; max( data ); } public static void main(String[] argv) { arrayforPerl javaPerl = new arrayforPerl(); javaPerl.maxProg(); } }

    I hope you can build on this

    A reply falls below the community's threshold of quality. You may see it by logging in.