On Fri, Dec 13, 2013 at 2:37 PM, Mike Flannigan <mikef...@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)