Ivan Gromov wrote:
>
> I have trouble with embedding Perl in C. I would like to replace some
> subroutine (exactly it is print function) in Perl script without
> changing this script.
>
> #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;
> }
>
> Is it possible? And how can I do it? Where can I find information about
> this subject?
> Or how I can replace any perl function?
>
> I was looking for any information dealing with my problem, but I
> haven’t found anything yet. Any help is much appreciated.
print() is one of the built-in functions that can't be overridden. You will have
to use a source filter or simply edit your Perl program. Take a look at
perldoc perlfilter
for guidance on the former option.
By the way, you have an argument count of 3 in your call to perl_parse, but the
command_line array has only two elements. It shouldn't cause any problems, it's
just wrong :)
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/