Embedding Perl in C: Replacing some subroutine in a Perl script from a C program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • IvanIV
    New Member
    • Jul 2008
    • 1

    Embedding Perl in C: Replacing some subroutine in a Perl script from a C program

    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:
    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; 
    }
    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
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Ask on the C forum since this is really a C question. Personally though, I don't know the answer.

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      That said, I am moving this question to the C forum so that the Experts there may answer it.

      Regards,

      Jeff

      Comment

      Working...