Bhavikatti has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I am a newbie to perl and know nothing of Perl . I want to embed perl in my C code.I work on Visual Studio in Windows. The perl code should do something like this. 1) It should ask for user on command line to input 2 xml files and then it should handover the names of these files to my C code which will do post processing on the contents of these files. 2) The perl code should also be able to call my C functions based on the number entered on command line by the user. I have referred the document perlembed.pod and tried to execute the code in section "Maintaining a persistent interpreter" in visual studio C++ environment. But the output is not as expected in the document.The test.pl is never executed. I will just give a glimpse of what I want to do #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl = NULL; int _tmain(int argc, _TCHAR* argv[]) { UInt8 char * arg1,*arg2; //Execute some C code over here. // Allocate a perl interpreter memory and then perl code should wait on DOS prompt for user to enter the file names and // these file names would be asssigned to arg1 and arg2.Now My C code will do processing on contents of these files. // And also I should be able to call some C functions from a perl script code.something like this number = perlgetnumber();// Number pressed by the user. //Call some Functions based on the number. // Deallocate the perl interpretr memory and quit. } Can anybody in the group give me Embedded (C and Perl) code . It will take a lot of effort to learn and do it. Please guide me. Thanks in Advance. Anand

Replies are listed 'Best First'.
Re: Embedding Perl and C
by ww (Archbishop) on Sep 26, 2009 at 13:23 UTC
    Properly formatted:

    Hi all,

    I am a newbie to perl and know nothing of Perl.
    I want to embed perl in my C code.I work on Visual Studio in Windows.

    The perl code should do something like this.

    1. It should ask for user on command line to input 2 xml files and then it should handover the names of these files to my C code which will do post processing on the contents of these files.
    2. The perl code should also be able to call my C functions based on the number entered on command line by the user.

    I have referred the document perlembed.pod and tried to execute the code in section "Maintaining a persistent interpreter" in visual studio C++ environment. But the output is not as expected in the document.The test.pl is never executed.

    I will just give a glimpse of what I want to do

    #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl = NULL; int _tmain(int argc, _TCHAR* argv[]) { UInt8 char * arg1,*arg2; //Execute some C code over here. // Allocate a perl interpreter memory and then perl code should wai +t on DOS prompt for user to enter the file names and // these file names would be asssigned to arg1 and arg2.Now My C co +de will do processing on contents of these files. // And also I should be able to call some C functions from a perl s +cript code.something like this number = perlgetnumber();// Number pressed by the user. //Call some Functions based on the number. // Deallocate the perl interpretr memory and quit. }

    Can anybody in the group give me Embedded (C and Perl) code.
    It will take a lot of effort to learn and do it.

    Please guide me.

    Thanks in Advance.
    Anand

    Re "give me Embedded (C and Perl) code" please see http://www.rentacoder.com. This isn't it.

    Others have pointed to the Monastery's markup guidelines; you should also see On asking for help and How do I post a question effectively?. Once you have made your own best effort to write the code you seek, post that and the error messages it produces (if any) or a precise description of how it fails to do what you expected. Then, you may expect more specific help.

Re: Embedding Perl and C
by biohisham (Priest) on Sep 26, 2009 at 09:48 UTC
    I can only provide you this link I got from a reply to this node Learning XS dmake problem in good spirit, you might find it useful since it sounds related to extending and embedding Perl.

    Other than this, Welcome to Perl Monks and you may want to invest time taking a look at Markup in the Monastery for convenience.


    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.
Re: Embedding Perl and C
by zwon (Abbot) on Sep 26, 2009 at 09:12 UTC

    There are some useful tips and links under the textarea into which you typed your question:

    Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!

    Please edit your question so it would be more readable!