XS (Perl)

XS (Perl)

XS is an interface through which a Perl program can call a C or C++ language subroutine. The letters stand for eXternal Subroutine, or xsub, where "external" means external to Perl, i.e. written in some other language.

It may be desirable for a Perl program to invoke a C subroutine in order to handle very CPU or memory intensive tasks, to interface with hardware or low-level system facilities, or to make use of existing C subroutine libraries.

The Perl interpreter is a C program, so in principle there is no obstacle to calling from Perl to C. However, the XS interface is complex, and using it requires some understanding of the interpreter. The earliest reference on the subject was the [http://search.cpan.org/dist/perl/pod/perlguts.pod perlguts] POD, the word "guts" suggesting the highly technical nature of the material.

Subroutine libraries in Perl are called "modules", and modules that contain xsubs are called "XS modules". Perl provides a framework for developing, packaging, distributing, and installing modules. To create an XS module, h2xs is first used to create an empty module. Next, C subroutines are added, and the calling interfaces to the C subroutines are specified with a specialized glue language (also referred to as XS). Finally, the module is compiled, tested, and installed with make.

Once an XS module is installed, it can be loaded into a Perl program with a use statement, like an ordinary Perl module. Once the module is loaded, the C subroutines can be called from Perl code, as if they were written in Perl.

XS modules are not without drawbacks. They are difficult to write and maintain, and they may only be installed if a C compiler and the headers that the Perl interpreter were compiled against are available. Also, new versions of Perl may break binary compatibility; if this happens, all XS modules must be recompiled.

It is also possible to write XS modules that wrap C++ code. Doing so is mostly a matter of wrestling with the module build system. Details on how to do this are given [http://www.johnkeiser.com/perl-xs-c++.html here] .

References

* Jenness, Tim & Cozens, Simon (2002). "Extending and Embedding Perl". Greenwich: Manning Publications Co. ISBN 1-930110-82-0

External links

* [http://search.cpan.org/~nwclark/perl-5.8.8/pod/perlxs.pod perlxs] Perl XS application programming interface
* [http://search.cpan.org/~nwclark/perl-5.8.8/pod/perlxstut.pod perlxstut] Perl XS tutorial
* [http://search.cpan.org/author/NWCLARK/perl-5.8.8/pod/perlguts.pod perlguts] Perl internal functions for those doing extensions
* [http://search.cpan.org/~nwclark/perl-5.8.8/pod/perlapi.pod perlapi] Perl API listing (autogenerated)
* [http://world.std.com/~swmcd/steven/perl/pm/xs/intro/index.html XS Mechanics] tutorial
* [http://www.johnkeiser.com/perl-xs-c++.html Perl and C++] building XS modules for C++


Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • PERL — Paradigmen: prozedural, modular, teilweise objektorientiert Erscheinungsjahr: 1987 Entwickler: Larry Wall, Perl Porter Aktuelle  …   Deutsch Wikipedia

  • Perl (Programmiersprache) — Perl Paradigmen: prozedural, modular, teilweise objektorientiert Erscheinungsjahr: 1987 Entwickler: Larry Wall, Perl Porter Aktuelle Version …   Deutsch Wikipedia

  • Perl — Desarrollador(es) Larry Wall www.perl.org Información general Paradigma multiparadigma, funcional, im …   Wikipedia Español

  • Perl 6 — Apparu en Spécification : 2001 2011, mise en œuvre partielle par Rakudo Star Auteur …   Wikipédia en Français

  • Perl 6 — Saltar a navegación, búsqueda Perl 6 Paradigma: multiparadigma Apareció en: 2000 Diseñado por: Larry Wall y la comunidad Perl Tipo de dato: Dinámico y estático Implementaciones …   Wikipedia Español

  • Perl — Семантика: мультипарадигменный: императивный, объектно ориентированный, функциональный Тип исполнения: интерпретатор Появился в: 1987 Автор(ы) …   Википедия

  • Perl 5 — Perl (langage) Pour les articles homonymes, voir Perl. Apparu en 1987 …   Wikipédia en Français

  • Perl Compatible Regular Expressions — Original author(s) Philip Hazel Stable release 8.20 / 2011 10 21; 25 days ago (2011 10 21) Written in C …   Wikipedia

  • Perl Mongers — is part of The Perl Foundation and provides services to Perl user groups. Perl Mongers was created in 1998 as a stand alone organization by Brian D Foy who formed the first Perl users group, the New York Perl Mongers, or NY.pm, in 1997 at the… …   Wikipedia

  • Perl 6 — Класс языка: Мультипарадигмальный Появился в: 2000 …   Википедия

  • PERL, JOSEPH — (1773–1839), author of significant satirical works and leading figure in the Galician haskalah . Perl was born in Tarnopol, where he spent most of his life. In his youth he was attracted to Ḥasidism and acquired knowledge of the movement s way of …   Encyclopedia of Judaism

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”