Skip to Content
Advanced Perl Programming, 2nd Edition
book

Advanced Perl Programming, 2nd Edition

by Simon Cozens
June 2005
Intermediate to advanced content levelIntermediate to advanced
298 pages
7h 28m
English
O'Reilly Media, Inc.
Content preview from Advanced Perl Programming, 2nd Edition

Chapter 9. Inline Extensions

Although Perl is a very powerful language, there are still some things that it cannot do by itself: it can’t communicate directly with hardware or take advantage of complex mathematical libraries. Other things it can do, but not very quickly: you can ask Perl to rotate an image by reading in and parsing the image file format, doing all the transformations on a really big array, and writing it out again, but that takes a lot of time and effort. It’s far better to ask a C library to do this for you, and the way to do this is to write an extension to allow Perl to talk to the C library. In fact, many graphical interfaces to Perl are merely extensions talking to the relevant C libraries.

The usual way to write an extension to bridge Perl and C is to use a complex and awkward intermediary language called XS (extension subroutines). If you want to do things the complex and awkward way, I suggest reading perlxstut in the Perl documentation, or my Extending and Embedding Perl (Manning). However, since one of the cardinal virtues of a Perl programmer is laziness, there has to be a less complex and awkward way to do it, right?

Thankfully, there is; Brian Ingerson got fed up with writing XS and ended up writing a very clever Perl module called Inline to do it for him. As we’ll see later in the chapter, Inline has become generalized to handle languages other than C, so the module we’ll look at for now is called Inline::C .

Simple Inline::C

The idea behind Inline::C ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Perl Programming

Advanced Perl Programming

Sriram Srinivasan
Perl in a Nutshell, 2nd Edition

Perl in a Nutshell, 2nd Edition

Nathan Patwardhan, Ellen Siever, Stephen Spainhour

Publisher Resources

ISBN: 0596004567Errata Page