Hi All,
I have trouble with embedding a Perl interpreter into a C program. I would like to replace some subroutine in a Perl script without changing this script from my C program. I need replace (override build-in function): print() and exit() functions. I know that in Perl script I can’t override print(), but for exit() function I can:
Is it possible to override print() and exit() from my C program? And how can I do it? Where can I find information about this subject?
I was looking for any information dealing with my problem, but I haven’t found anything yet. Any help is much appreciated.
Thanks & Regards in advance
Ivan Gromov
I have trouble with embedding a Perl interpreter into a C program. I would like to replace some subroutine in a Perl script without changing this script from my C program. I need replace (override build-in function): print() and exit() functions. I know that in Perl script I can’t override print(), but for exit() function I can:
Code:
use subs ‘exit’;
sub exit
{
CORE::print “Overriding exit”;
}
exit(1);
//It is C program to create Perl interpreter
#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter *my_perl; // Perl interpreter in my program
int main(int argc, char **argv)
{
char* command_line[] = {"", “./script.pl”}; // script.pl is perl script
my_perl = perl_alloc();
perl_construct(my_perl);
//maybe, in this place I should carry out some function to replace print()?
perl_parse(my_perl, NULL, 3, command_line, (char **)NULL);
perl_run(my_perl);
perl_destruct(my_perl);
perl_free(my_perl);
return 0;
}
I was looking for any information dealing with my problem, but I haven’t found anything yet. Any help is much appreciated.
Thanks & Regards in advance
Ivan Gromov
Comment