Inline::C is the stuff that dreams are made of. I'm serious.
Here's how you use
Inline::C:
- Find some C code that you want to use, preferably in
ANSI C format, which is pretty standard stuff.
- Plonk your C code into Perl using a here document
parameter to use Inline::C
- Use the functions directly from Perl as if they were
there all along.
I know, it sounds too good to be true, but it is. No XS
is required, which is good because most of that stuff never made much
sense to the average Perl hacker.
If you have just a library file, like a shared library,
or a statically linked one, it's not that hard to plow
that into
Inline::C using the header file. It's just
a few more options.
If you're feeling particularly adventurous, you would
try and convert any library output from nasty C structures
into Perl ones using the low-level conversion routines
that are part of XS. For instance, instead of getting back
a linked list in C, you could convert to an AV*, or Array
Value, so that it is just a regular Perl array, and it
just requires making a quick "wrapper" function. Since
you're working one-on-one with the Perl interpreter,
right inside it, actually, you can make hashes, classes,
the works.
As a bonus, when you're merging your C code with Perl,
you can choose
when Perl is better and when C is. You can work back and
forth within the same program as required. So this way
you can have the output of the C function go through
an intermediate Perl function, sorting or substituting
perhaps, and then back into C for some final work before
being used in the main Perl program. It's really
incredible what you can do.
I know, I'm gushing, but it is really very cool stuff.