bichonfrise74 has asked for the wisdom of the Perl Monks concerning the following question:

I have always used Text::CSV but I'm wondering whether I should switch to Text::CSV_XS. I looked at both modules and it seems that Text::CSV is the older module and it can only deal with ascii characters.

Aside from these differences, is there a reason to use one from the other?
  • Comment on Difference between Text::CSV_XS and Text::CSV

Replies are listed 'Best First'.
Re: Difference between Text::CSV_XS and Text::CSV
by ikegami (Patriarch) on Jun 25, 2009 at 00:27 UTC

    Text::CSV is actually only a thin wrapper for Text::CSV_XS (prefered) and Text::CSV_PP (fallback).

    it seems that Text::CSV [...] can only deal with ascii characters.

    Both implementation can handle binary characters (with Binary=>1). In fact, both implementations have the same interface and capabilities.

    I looked at both modules and it seems that Text::CSV is the older module

    Both are kept in sync. Both had a released in the last two months.

    The only differences should be

    • Text::CSV_XS is faster
    • Text::CSV_XS can be harder to install for some people.
Re: Difference between Text::CSV_XS and Text::CSV
by dreadpiratepeter (Priest) on Jun 25, 2009 at 00:04 UTC
    The difference is that Text::CSV_XS is written in c so it is much faster than Text::CSV which is a pure-Perl module. If you have a C compiler, I would recommend using the XS version


    -pete
    "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."

      As ikegami already mentioned, Text::CSV is just a wrapper over Text::CSV_XS nowadays, but what he did not mention is that Text::CSV bundles Text::CSV_PP which is the pure-perl implementation of Text::CSV_XS.

      Text::CSV_XS is about 50 times faster than the pure-perl version. Text::CSV is the module of choice, which you can speed up, even afterwards, by installing the XS version.

      I maintain the XS version, and communicate with the author of the pure-perl version, so once Text::CSV_XS is updated to a new release, the wrapper modules can follow within days with the matching pure-perl version.


      Enjoy, Have FUN! H.Merijn
Re: Difference between Text::CSV_XS and Text::CSV
by alexlc (Beadle) on Jun 25, 2009 at 00:16 UTC
    Aside from the differences you mentioned, the XS version should be somewhat faster, or perhaps consume less memory.
    XS stands for eXternal Subroutine, and is a method for writing perl functions in C. This is used extensively to either tie existing C libraries to perl, or to write more efficient or faster functions.

    PerlXS is the documentation page on XS if you are interested.

    Generally module names containing XS denote that some or all of the module is in fact written in C. I am making the assumption that because you asked what other reasons there are for using the XS version, you didn't know this. My apologies if I am incorrect.
    -- AlexLC