Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

reading C data structure

by asura (Initiate)
on Sep 17, 2012 at 22:19 UTC ( [id://994131]=perlquestion: print w/replies, xml ) Need Help??

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: reading C data structure
by GrandFather (Saint) 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 (Canon) on Sep 17, 2012 at 22:52 UTC
    Here is a small sample from CPAN of some of the ways to interpret your question:
    Data::Struct
    Simple struct building
    Data-Struct-1.701 - 23 Nov 2011 - Johan Vromans
    
    SOOT::Struct
    Perl interface to generate new C-level struct types
    SOOT-0.17 - 25 Dec 2011 - Steffen Müller
    
    Win32::API::Struct
    C struct support package for Win32::API
    Win32-API-0.68**** (3 Reviews) - 10 Apr 2012 - Cosimo Streppone
    
    Thrift::Parser::Type::Struct
    Struct type
    Thrift-Parser-0.03 - 16 Sep 2012 - Eric Waters
    
    Class::Struct::FIELDS
    Combine Class::Struct, base and fields
    Class-Struct-FIELDS-1.1 - 05 Jul 2001 - B. K. Oxley (binkley)
    
    Class::Struct
    declare struct-like datatypes as Perl classes
    perl-5.16.1*** (9 Reviews) - 08 Aug 2012 - Ricardo SIGNES
    
    Inline::SLang::Struct
    Support for structures
    Inline-SLang-1.00 - 04 Jan 2005 - Douglas Burke
    
    Inline::Struct
    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.
                       -SNL

Re: reading C data structure
by davido (Cardinal) 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.


    Dave

      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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-19 05:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found