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

Re: Perl XS Beginners

Thread Previous | Thread Next
From:
wolfsage
Date:
December 13, 2013 19:39
Subject:
Re: Perl XS Beginners
Message ID:
CAJ0K8bjZAa1S3XfEfhwDQQRrTekgpXE5FfwxgwXA9jzS0Lq5qg@mail.gmail.com
On Fri, Dec 13, 2013 at 2:37 PM, Mike Flannigan <mikeflan@att.net> wrote:
>
> I for one had to look up what XS is:
> http://en.wikipedia.org/wiki/XS_%28Perl%29
>
> 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
Devel::SawAmpersand.

Hope that helps.

-- Matthew Horsfall (alh)

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About