develooper Front page | perl.xs | Postings from December 2013

Re: Perl XS Beginners

Thread Previous | Thread Next
December 13, 2013 19:39
Re: Perl XS Beginners
Message ID:
On Fri, Dec 13, 2013 at 2:37 PM, Mike Flannigan <> wrote:
> I for one had to look up what XS is:
> It is a an interface through which a program written
> in the Perl programming language can call a C or C++
> language subroutine.
> I don't know enough about C or C++ to answer why a
> 'system' command or 'exec' command wouldn't do the
> same thing.

XS is how you can interface with other libraries written in C/C++.

For example, DBD::mysql interfaces with the MySQL Client libraries
which are written in C.
You wouldn't want to have to call system('mysql -e ...') or
exec('mysql -e ...') to invoke the command line client every time you
wanted to issue a SQL query, the overhead would be outrageous.

Also, many C libraries don't have command line interfaces that you can
call directly.

It's also how you write Perl modules in C that are generally much
faster than their Pure-Perl variants, think JSON::XS vs JSON::PP.

Another use of XS is to write Perl modules that make use of parts of
perl's internals that aren't exposed in Pure-Perl land, like

Hope that helps.

-- Matthew Horsfall (alh)

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About