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

Dear Monks,

Please could somebody explain in detail what the following does? It seems to be a peculiar structure with regard to use of space (or not). What is the xx.pm for? What is -pi.bak? What is xx.pm? I really don't understand any of it.
Tmp>perl -pi.bak -we"s{Text::CSV}{Text::CSV_XS}g" xx.pm

Replies are listed 'Best First'.
Re: Explanation of Perl one-liner required
by moritz (Cardinal) on Sep 28, 2009 at 11:01 UTC
    You can read about the various command line switches in perlrun, the substitution should be explained in perlintro or perlretut.

    The xx.pm is simply a command line argument to the script.

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: Explanation of Perl one-liner required
by jakobi (Pilgrim) on Sep 28, 2009 at 11:16 UTC

    rewrite the options to something 'more standard', then it's easier to read (I ignored the p being hidden in plain sight due to pi.bak and was also wondering for a sec):

    perl -w -i.bak -pe 's/Text::CSV/Text::CSV_XS/g' FILE_BEING_EDITED

    :)
    Peter

Re: Explanation of Perl one-liner required
by Anonymous Monk on Sep 28, 2009 at 11:19 UTC
    This is indeed a peculiar structure which will universally fix old Text::CSV installations and upgrade them. You can read more about it by doing perldoc Text::CSV::Upgrade (you will need a version of Text::CSV newer than 0.59, if you don't have that installed, just download it from CPAN and execute the command in the untarred directory).
      I do not agree. A modern Text::CSV will use the XS-version if available and the Pure Perl version if XS is not available. So there is no need to "upgrade" your scripts. As per the docs:
      Text::CSV provides facilities for the composition and decomposition of comma-separated values using Text::CSV_XS or its pure Perl version.

      If there is anything you should do, then it is to replace Text::CSV_XS by Text::CSV to make your script more universally applicable.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        You're missing the context. He doesn't have a modern Text::CSV, and it's easier instructing this particular monk to install Text::CSV_XS (simple ppm command) than to have him upgrade Text::CSV (which would require installation of make tools, an exercise requiring at least 5 posts to explain to this monk).
      Forgot, sorry, the more correct invocation is

      perl -peb.cak -we"s{Text::CSV}{Text::CSV_XS}g" xx.pm