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

Dear Masters,

Do you happen to know if there exist any C libary that enable us to create hash - as well as other complex data structure perhaps, eg. AoA,HoA,etc - (almost) as simple as Perl does, for coding in C?

Any pointers (links) would be greatly appreciated.

---
neversaint and everlastingly indebted.......
  • Comment on C Library for Perl-like Hashes Creation

Replies are listed 'Best First'.
Re: C Library for Perl-like Hashes Creation
by Fletch (Bishop) on Sep 06, 2006 at 14:14 UTC

    The GTK+ toolkit sits on top of a C library called GLib (which can be used outside of GTK+ apps) which provides some advanced datatypes which might be what you're looking for.

    Of course you can always just embed Perl in your C and use the real thing.

Re: C Library for Perl-like Hashes Creation
by wojtyk (Friar) on Sep 06, 2006 at 15:04 UTC
    Dunno about C, but C++ STL has rough equivalents of Perl datatypes.

    A perl hash is somewhat like an STL map.
    A perl array is somewhat like an STL vector.
    A perl scalar is somewhat like an STL string.

    Homogenization isn't as easy of course, since you have to deal with types in C/C++, but the basic dynamic data structure is essentially there.

Re: C Library for Perl-like Hashes Creation
by derby (Abbot) on Sep 06, 2006 at 15:14 UTC

    The problem is there are tons of them (check out freshmeat.net). If I had to do it, I would go with what [id://fletch] said - glib -- it's the closest thing to standard.

    -derby

    update: Just saw the almost as simple as perl requirement -- yikes! Any C lib for complex data structures will only be *almost as simple* only if you have a very loose interpetation of the word almost (and simple).

Re: C Library for Perl-like Hashes Creation
by randyk (Parson) on Sep 06, 2006 at 23:24 UTC
    For portability, and perhaps general availability, you may want to take a look at tables and arrays in Apache's APR library. The docs for APR::Table are useful for seeing the Perl equivalent.
Re: C Library for Perl-like Hashes Creation
by planetscape (Chancellor) on Sep 07, 2006 at 16:03 UTC

    It's entirely possible I'm barking up the wrong tree, but if you have in mind, perhaps, some sort of data exchange, you may wish to have a look at YAML (spec).

    HTH,

    planetscape