By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,694 Members | 1,882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,694 IT Pros & Developers. It's quick & easy.

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

P: 1
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:
Expand|Select|Wrap|Line Numbers
  1. use subs ‘exit’;
  2. sub exit 
  3. {
  4. CORE::print “Overriding exit”;
  5. }
  6. exit(1);
  7.  
  8. //It is C program to create Perl interpreter
  9. #include <EXTERN.h> 
  10. #include <perl.h> 
  11.  
  12. static PerlInterpreter *my_perl; // Perl interpreter in my program 
  13.  
  14. int main(int argc, char **argv) 
  15.  
  16. char* command_line[] = {"", “./script.pl”}; // script.pl is perl script 
  17. my_perl = perl_alloc(); 
  18. perl_construct(my_perl); 
  19. //maybe, in this place I should carry out some function to replace print()? 
  20. perl_parse(my_perl, NULL, 3, command_line, (char **)NULL); 
  21. perl_run(my_perl); 
  22. perl_destruct(my_perl); 
  23. perl_free(my_perl); 
  24. return 0; 
  25.  
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
Jul 14 '08 #1
Share this Question
Share on Google+
2 Replies


KevinADC
Expert 2.5K+
P: 4,059
Ask on the C forum since this is really a C question. Personally though, I don't know the answer.
Jul 14 '08 #2

numberwhun
Expert Mod 2.5K+
P: 3,503
That said, I am moving this question to the C forum so that the Experts there may answer it.

Regards,

Jeff
Jul 15 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.