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

Dear perl monks Please treat a begginer kindly. I would like to know if there is a (simple) way of incorporating a C-program (or any other external program or script) into a perl script such that data structures are shared. I realise one can use a system() command to the external program, but can I do it so that the external program has access to a perl hash, for example? any answers, including ones telling me how to ask questions more efficiently, will be fully appreciated.

Replies are listed 'Best First'.
Re: Incoporating C programs
by Molt (Chaplain) on Oct 30, 2002 at 17:27 UTC

    In general if you're just beginning to look into this I'd advise you to look at Inline::C, which allows you to embed your C in Perl and access Perl's data structures in a nice and simple way. The Cookbook which comes as part of the distribution is a nice tutorial on how to do the basics.

    ..oh, and I'd wish you luck, and point you at the Perldocs on perlguts and perlapi, they are most useful.

Re: Incoporating C programs
by Steve_p (Priest) on Oct 30, 2002 at 17:28 UTC

    Yes, it is possible, but it isn't the easiest thing to do, or try to explain. First, you'll need to have a C compiler. I'm assuming that isn't a problem, even on Windows. Next, read the perlxstut document by entering

    perldoc perlxstut

    from the command-line. Despite its billing as a tutorial, it goes through a lot of things quickly. I would also suggest the book Extending and Embedding Perl. I'm still working through it now, but I would definitely suggest a thorough reading of Chapter 2 to do what it sounds like you want to do.