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

I'm getting a very peculiar error when I load the open pragma before I load the Text::CSV_XS module.

C:\strawberry>perl -MText::CSV_XS -Mopen=:encoding(UTF-8) -e 1 C:\strawberry>perl -Mopen=:encoding(UTF-8) -MText::CSV_XS -e 1 Bareword found where operator expected at C:/strawberry/perl/site/lib/ +Text/CSV_XS.pm line 3, near "1 H" (Missing operator before H?) syntax error at C:/strawberry/perl/site/lib/Text/CSV_XS.pm line 3, nea +r "1 H" BEGIN not safe after errors--compilation aborted at C:/strawberry/perl +/site/lib/Text/CSV_XS.pm line 23. Compilation failed in require. BEGIN failed--compilation aborted. C:\strawberry>perl -Mopen=:encoding(ASCII) -MText::CSV_XS -e 1 Bareword found where operator expected at C:/strawberry/perl/site/lib/ +Text/CSV_XS.pm line 3, near "1 H" (Missing operator before H?) syntax error at C:/strawberry/perl/site/lib/Text/CSV_XS.pm line 3, nea +r "1 H" BEGIN not safe after errors--compilation aborted at C:/strawberry/perl +/site/lib/Text/CSV_XS.pm line 23. Compilation failed in require. BEGIN failed--compilation aborted. C:\strawberry>head -23 C:/strawberry/perl/site/lib/Text/CSV_XS.pm package Text::CSV_XS; # Copyright (c) 2007-2011 H.Merijn Brand. All rights reserved. # Copyright (c) 1998-2001 Jochen Wiedmann. All rights reserved. # Portions Copyright (c) 1997 Alan Citterman. All rights reserved. # # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # HISTORY # # Written by: # Jochen Wiedmann <joe@ispsoft.de> # # Based on Text::CSV by: # Alan Citterman <alan@mfgrtl.com> # # Extended and Remodelled by: # H.Merijn Brand (h.m.brand@xs4all.nl) require 5.005; use strict; C:\strawberry>

What's causing this problem?

I'm running Strawberry Perl version 5.14.2, open version 1.08, and Text::CSV_XS version 0.85.

Jim

  • Comment on Peculiar Error When Loading open Pragma Before Text::CSV_XS Module
  • Download Code

Replies are listed 'Best First'.
Re: Peculiar Error When Loading open Pragma Before Text::CSV_XS Module
by ikegami (Patriarch) on Dec 24, 2011 at 10:32 UTC

    You can work around the problem by changing the line endings of Text/CSV_XS.pm from LF to CRLF.

    perl -i.bak -pe1 ...\Text\CSV_XS.pm

    You can find the file to fix using

    perldoc -l Text::CSV_XS

    The file is read-only, which you can circumvent using

    attrib -r ...\Text\CSV_XS.pm

      Interesting. can you explain why?


      Enjoy, Have FUN! H.Merijn

        Nope!

        There was talk on p5p (by Jan Dubois??*) about Perl having to correct the current source file position (when still near the top of the file) to take CRLF endings into account on Windows. Something about reading the source file as a text file, then having to reconstruct the buffer so it would be as if the file had been read as a binary file. Doing so requires assuming the lines end with CRLF. (Well, that's how I vaguely remember it.) I don't remember the context of that talk, but I figured this problem might be related since Perl is apparently treating the middle of a comment as source code.

        * — "Jan Dubois" would be an awesome porn star name. du = from the, of the, some; bois = wood, woods

Re: Peculiar Error When Loading open Pragma Before Text::CSV_XS Module
by Tux (Canon) on Dec 24, 2011 at 10:26 UTC

    There might be several problems. I think you need quotes:

    $ perl -Mopen=:encoding(UTF-8) -MText::CSV_XS -e 1 Badly placed ()'s. $ perl -Mopen=':encoding(UTF-8)' -MText::CSV_XS -we 1 $

    Though quotation on Windows might be different and it yields different errors:

    C:\Users\Tux>perl "-Mopen=:encoding(utf-8)" -MText::CSV_XS -we1 Bareword found where operator expected at C:/strawberry/perl/site/lib/ +Text/CSV_XS.pm line 3, near "1 H" (Missing operator before H?) Unquoted string "reserved" may clash with future reserved word at C:/s +trawberry/perl/site/lib/Text/CSV_XS.pm line 3. syntax error at C:/strawberry/perl/site/lib/Text/CSV_XS.pm line 3, nea +r "1 H" BEGIN not safe after errors--compilation aborted at C:/strawberry/perl +/site/lib/Text/CSV_XS.pm line 23. Compilation failed in require. BEGIN failed--compilation aborted.

    There is a related known problem, which has been solved in IO. See this RT tcket for all the details and this patch to blead for the fix.


    Enjoy, Have FUN! H.Merijn
      There is a related known problem, which has been solved in IO. See this RT ticket for all the details and this patch to blead for the fix.

      Tux,

      It was exactly this IO patch I was checking for when I stumbled upon this new, different problem. I was revisiting the thread from early October with the subject Why Doesn't Text::CSV_XS Print Valid UTF-8 Text When Used With the open Pragma?. Since then, I've upgraded from Strawberry Perl 5.12 to 5.14, so I was naïvely testing to see if the patch to fix the behavior of the open pragma had been applied to this newer version of Perl.

      Needless to say, it isn't fixed in 5.14.2.

      Jim