JPERL Beta PERL Access routines in Java --------------------------------------------------------------------- Copyright (c) 1998, S Balamurugan, Texas Instruments India. All Rights Reserved. --------------------------------------------------------------------- Permission to use, copy, modify, and distribute this software and its documentation for NON-COMMERCIAL purposes and without fee is hereby granted provided that this copyright notice appears in all copies. Please refer LICENCE for further important copyright and licensing information. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHOR OR TEXAS INSTRUMENTS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. --------------------------------------------------------------------- Accessing PERL from cpp * Initialisation and Close routines ----------------------------------- int PLInit(char *perlfile); // Need to call init with the PERL file before using any other routine // Refer example.c for more details int PLClose(); // Closes interpretter and frees memory * Making PERL calls ------------------- // All functions return number of elements returned from PERL, // return value is passed through retval reference. Any number and // type of argument can be passed. Need to provide the format of the // arguments. In case of passing Arrays need to pass length and then // the array. See example below Valid formats ------------- %d - int %f - double %s - char * (String) %I - int * (Array of integer. Need to pass length before int *) %F - double * (Array of double . Need to pass length before double *) %S - char ** (Array of string. Need to pass length before char **) e.g. PLCall(retval,"MyFunc","%I",len,Int_Array); // Returns scalar string int PLCall(char *&retval, char *fname, char *format, ...); // Returns scalar integer int PLCall(int &retval, char *fname, char *format, ...); // Returns scalar double int PLCall(double &retval, char *fname, char *format, ...); // Returns array of int int PLCall(int *&retval, char *fname, char *format, ...); // Returns array of double int PLCall(double *&retval, char *fname, char *format, ...); // Returns array of string and PERL Hash // Hash is returned as array of char *, with alternate elements being // key and values int PLCall(char **&retval, char *fname, char *format, ...); Examples -------- //Passing scalar, returning string array PLInit("t.pl"); char **AS; int number_of_elements = PLCall(AS,"TestFunc","%s%f","Hai",(float)100); PLClose(); //Passing array of int and double, returning Hash PLInit("t.pl"); char **AS; int IA[] = { 10,20,30 }; double DA[] = { 0.10, 0.20 } ; PLCall(AS,"TestFuncAI","%I%F",3,IA,2,DA); // Note: Passing length before arr. PLClose(); // Refer example.c for more information * Evalaluating PERL expressions ------------------------------- // Evaluates PERL expression in command. Returns string array in retval int PLEval(char **&retval, char *command); Example ------- char **EvalRet; int ct = PLEval(EvalRet,"$a = 'MyString'; $b = reverse($a); return ($a,$b);"); for(int i=0;i