Extending and Embedding Perl
Tim Jenness and Simon Cozens
  • August 2002
  • ISBN 9781930110823
  • 384 pages

Extending and Embedding Perl explains how to expand the functionality and usefulness of the Perl programming language and how to use Perl from C programs. It begins simply but also covers complex issues using real code examples from the Perl source. The book discusses how to write interfaces to C libraries (as well as C++ and Fortran libraries). It shows you how to implement Perl callbacks for C libraries, how to pass Perl hashes and arrays between Perl and C, and how to use the Perl Data Language infrastructure to improve the speed of array operations.

Additionally, the book peers under the hood to see how the Perl programming language really works by looking at the interpreter. The make-up of Perl variables is discussed along with details on how a Perl program is parsed and converted to executable code.

Table of Contents show full



about this book

author online

about the cover illustration

1. C for Perl programmers

1.1. Hello, world

1.2. The C compiler

1.3. Header files

1.4. The main function

1.5. Variables and functions

1.6. Data types

1.7. Casting

1.8. Control constructs

1.9. Macros and the C preprocessor

1.10. Library functions

1.11. Summary

2. Extending Perl: an introduction

2.1. Perl modules

2.2. Interfacing to another language: C from XS

2.3. XS and C: taking things further

2.4. What about Makefile.PL?

2.5. Interface design: part 1

2.6. Further reading

2.7. Summary

3. Advanced C

3.1. Arrays

3.2. Pointers

3.3. Strings

3.4. Structures

3.5. File I/O

3.6. Memory management

3.7. C Traps for the Perl programmer

3.8. Further reading

3.9. Summary

4. Perl’s variable types

4.1. General concepts

4.2. Scalar variables

4.3. Magic variables: SvPVMG

4.4. Array variables

4.5. Hashes

4.6. Globs

4.7. Namespaces and stashes

4.8. Lexical 'my' variables

4.9. Code blocks

4.10. Further reading

4.11. Summary

5. The Perl 5 API

5.1. Sample entry

5.2. SV functions

5.3. AV functions

5.4. HV functions

5.5. Miscellaneous functions

5.6. Summary

6. Advanced XS programming

6.1. Pointers and things

6.2. Filehandles

6.3. Typemaps

6.4. The argument stack

6.5. C structures

6.6. Arrays

6.7. Callbacks

6.8. Other languages

6.9. Interface design: part 2

6.10. Older Perls

6.11. What’s really going on?

6.12. Further reading

6.13. Summary

7. Alternatives to XS

7.1. The h2xs program

7.2. SWIG

7.3. The Inline module

7.4. The PDL::PP module

7.5. Earlier alternatives

7.6. Further reading

7.7. Summary

8. Embedding Perl in C

8.1. When to embed

8.2. When not to embed

8.3. Things to think about

8.4. 'Hello C' from Perl

8.5. Passing data

8.6. Calling Perl routines

8.7. Using C in Perl in C

8.8. Embedding wisdom

8.9. Summary

9. Embedding case study

9.1. Goals

9.2. Preparing the ground

9.3. Configuration options

9.4. Testing options

9.5. Summary

10. Introduction to Perl internals

10.1. The source tree

10.2. The parser

10.3. The tokenizer

10.4. Op code trees

10.5. Execution

10.6. The Perl compiler

10.7. Further reading

10.8. Summary

11. Hacking Perl

11.1. The development process

11.2. Debugging aids

11.3. Creating a patch

11.4. Perl 6: the future of Perl

11.5. Further reading

11.6. Summary

Appendix A: Perl’s typemaps

Appendix B: Further reading

Appendix C: Perl API index


What's inside

  • C For The Perl Programmer
  • Basic and Advanced XS
  • Embedding Perl in C Programs
  • Perl Internals
  • An API reference for the internal C interface to Perl
  • A reference on the typemap system
  • Embedding Perl into the mutt mail reader

About the authors

A Perl developer for 7 years, Tim Jenness has ten modules on CPAN including two that are distributed as part of the core Perl distribution (File::Temp and Pod::LateX).

Simon Cozens the author of Beginning Perl, was the release manager for the first four releases of the Perl 6 runtime engine, Parrot.

eBook $35.99 PDF only

FREE domestic shipping on three or more pBooks