Operating System - Linux
1825011 Members
4645 Online
109678 Solutions
New Discussion юеВ

Re: How to call a PERL subroutine from a C/C++ code

 
CA1490051
Frequent Advisor

How to call a PERL subroutine from a C/C++ code

Hi All,

I have installed Active PERL-5.8.8 and i want to call a subroutine from a C/C++ Program.

For this what all i have to install (any special Libraries)

Can anyone help me out of this .

thanks and regards
Vikram
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: How to call a PERL subroutine from a C/C++ code

Hi Vikram:

This should be the same as any external program call. No special libraries are needed. Depending upon what you want to achieve, you could simply use 'system()'. Of course, this runs the program defined by its argument and then returns control to the caller. You could also 'execl' the Perl code replacing your program with it. Otherwise, perhaps you want to 'fork()' the Perl program (script or module) as a child process of your C code. For inter-C/Perl communication look to a 'pipe'. Everything depends upon what you want to do and what control you need to have.

Regards!

...JRF...
CA1490051
Frequent Advisor

Re: How to call a PERL subroutine from a C/C++ code

Hi JRF,

Thank you for the reply.

I want to parse a file so i am plaaning to use PERL script as it will be very easy to parse the file using PERL because buitin functions like split(), chomp() etc,

After parsing i want to store this contents in a hash table. From this i can continue the C++ module to work on the same hash table elements.

this is all i want to achieve.

Please let me know your inputs to this
CA1490051
Frequent Advisor

Re: How to call a PERL subroutine from a C/C++ code

Hi JRF,

Thank you for the reply.

I want to parse a file so i am plaaning to use PERL script as it will be very easy to parse the file using PERL because buitin functions like split(), chomp() etc,

After parsing i want to store this contents in a hash table. From this i can continue the C++ module to work on the same hash table elements.

this is all i want to achieve.

Please let me know your inputs to this

thanks and regards
Vikram
Ralph Grothe
Honored Contributor

Re: How to call a PERL subroutine from a C/C++ code

Hi Vikram,

from a shell type "perldoc perlembed".
Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: How to call a PERL subroutine from a C/C++ code

Hi Vikram,

if it's more than just a system() or execvp() syscall then
from a shell type "perldoc perlembed" and read.
Madness, thy name is system administration