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

Folks,

Is there a way (or many !) to use the definition of structures in C header files in a Perl program ? The idea is to use already-defined structures from a previous project while saving - if possible - time re-writing them from scratch in Perl.

Thanks.

Replies are listed 'Best First'.
Re: C structures ?
by derby (Abbot) on Dec 13, 2005 at 18:49 UTC

    Why stop at the structures? If you have a decent library to go with the structures, use it also. <blatant_xp_grasp>Check out my Inline::C tutorial that uses the c services lib</blatant_xp_grasp>.

    -derby
Re: C structures ?
by CountOrlok (Friar) on Dec 13, 2005 at 17:51 UTC
    Maybe h2ph is the answer to your prayers. (man h2ph)
    -imran
Re: C structures ?
by samtregar (Abbot) on Dec 13, 2005 at 19:24 UTC
    While Inline::C may help you'll probably have to write some interface code if you have large and/or complex structures. SWIG may be a better tool for this job since it has lots of automated interface generation built-in and can handle just about any legal C structure. I used it when I was working on Coagula and it was a real champ.

    -sam