Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

reading C data structure

by asura (Initiate)
on Sep 17, 2012 at 22:19 UTC ( #994131=perlquestion: print w/ replies, xml ) Need Help??
asura has asked for the wisdom of the Perl Monks concerning the following question:

How do I read a C data structure from a perl script ?

Comment on reading C data structure
Replies are listed 'Best First'.
Re: reading C data structure
by GrandFather (Sage) on Sep 17, 2012 at 22:39 UTC

    You don't. Or, at least, your question is open to so many different interpretations it's not possible to know what you actually want to do.

    Things you may want to do are:

    1. Read binary data from a file written by a C application
    2. Pass data from XS back to Perl
    3. Recreate in Perl a data structure serialised by a C application
    4. Recreate in Perl a C data structure specified in a .h file
    5. any number of other possible scenarios I haven't thought of
    True laziness is hard work
Re: reading C data structure
by NetWallah (Abbot) on Sep 17, 2012 at 22:52 UTC
    Here is a small sample from CPAN of some of the ways to interpret your question:
    Simple struct building
    Data-Struct-1.701 - 23 Nov 2011 - Johan Vromans
    Perl interface to generate new C-level struct types
    SOOT-0.17 - 25 Dec 2011 - Steffen Müller
    C struct support package for Win32::API
    Win32-API-0.68**** (3 Reviews) - 10 Apr 2012 - Cosimo Streppone
    Struct type
    Thrift-Parser-0.03 - 16 Sep 2012 - Eric Waters
    Combine Class::Struct, base and fields
    Class-Struct-FIELDS-1.1 - 05 Jul 2001 - B. K. Oxley (binkley)
    declare struct-like datatypes as Perl classes
    perl-5.16.1*** (9 Reviews) - 08 Aug 2012 - Ricardo SIGNES
    Support for structures
    Inline-SLang-1.00 - 04 Jan 2005 - Douglas Burke
    Manipulate C structures directly from Perl.
    Inline-Struct-0.06*** (1 Reviews) - 11 Jun 2001 - Neil Watkiss 

                 I hope life isn't a big joke, because I don't get it.

Re: reading C data structure
by davido (Archbishop) on Sep 18, 2012 at 00:12 UTC

    It's unfortunate: The real question most probably has a good answer. But it's impossible to know what that answer is given the ambiguity and terseness in how you chose to communicate that question to us. I wish we knew what it is that you actually are trying to do.


      My apologies for the ambiguity. I have a variable in a C function (it is a uuid). A perl script needs to use this variable for some operation. Is there a way for me to read this variable from the perl script. I am trying to avoid writing it to a file and reading from it (expensive). Thanks in advance...

        If you want to communicate between two running processes, that will be much harder than just writing/reading the values to a tempfile.

        However, there is Convert::Binary::C, which was made for just that situation, debugging a remote process and dumping C structures from within Perl. Maybe that helps you.

        That really doesn't get us much further ahead. Do you want write code to call Perl from C (possible), or write code to call C from Perl (also possible), or call an existing C library function from Perl (possible too), or execute an existing Perl script from a C application passing a value through (possible) or execute an existing C application from a Perl script returning a value to the script (also possible), or something else?

        Maybe you should let us in on the secret of what you actually want to do?

        True laziness is hard work

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994131]
Approved by GrandFather
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2015-10-13 10:17 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (299 votes), past polls