Hello All.
I have a problem. I need persistent Perl interpreter in my C program and
a function, that can run my scripts and can make addition things with
data from the script. In the function I carry out set of perlapi
functions: perl_construct(), perl_parse(), perl_run and perl_destruct().
But Perl interpreter doesn’t run modules (I pass it as string in
perl_parse) after first using of the function.
//For instance, it is simple source that shows this problem:
#include <EXTERN.h>
#include <perl.h>
#include <stdio.h>
//it is simple fun, that run filename with module -Mstrict
void execScript (char* filename, PerlInterpreter *my_perl, int *err);
static PerlInterpreter *my_perl;
int main (int argc, char **argv, char **env)
{
int err = 0;
char *file_name = "testperl.pl";
char *command_line[] = {"","-Mstrict” ","testperl2.pl"};
int i = 0;
my_perl = perl_alloc();
//in this line will fail, because in testperl.pl we have ‘$ab’
without ‘our’
execScript (file_name, my_perl, &err);
//but these lines will be without fail, that is module ‘strict’
doesn’t run
for (i = 0; i < 2 ; i++)
{
execScript (file_name, my_perl, &err);
}
//similar as above
for (i = 0; i < 3; i++)
{
PERL_SET_CONTEXT( my_perl );
PL_perl_destruct_level = 1;
perl_construct(my_perl);
perl_parse(my_perl, NULL , 3, command_line, (char
**)NULL);
perl_run(my_perl);
PL_perl_destruct_level = 1;
perl_destruct(my_perl);
}
perl_free(my_perl);
return 0;
}
void execScript (char *script, PerlInterpreter *my_perl, int* err)
{
char *command_line[] = {"","-Mstrict",script};
int i = 0;
*err = 0;
if (my_perl == NULL)
{
printf ("\nmy_perl = NULL\n");
*err = -1;
return;
}
PERL_SET_CONTEXT( my_perl );
PL_perl_destruct_level = 1;
perl_construct(my_perl);
*err = perl_parse(my_perl, NULL , 3, command_line, (char
**)NULL);
if (*err != 0)
{
printf ("\nError in perl_parse\n");
PL_perl_destruct_level = 1;
perl_destruct(my_perl);
return;
}
perl_run(my_perl);
PL_perl_destruct_level = 1;
perl_destruct(my_perl);
return;
}
testperl.pl is:
$ab = 100;
print “testperl.pl. ab = $ab \n”;
testperl2.pl is:
$PQR = “Hello”;
print “$PQR from testperl2.pl \n”;
I don’t know what exactly do with my problem. I haven’t any ideas.
Any help is much appreciated.
Thanks & Regards in advance
Ivan Gromov
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/