in reply to Peculiar Error When Loading open Pragma Before Text::CSV_XS Module

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

Replies are listed 'Best First'.
Re^2: Peculiar Error When Loading open Pragma Before Text::CSV_XS Module
by Tux (Canon) on Dec 24, 2011 at 10:36 UTC

    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

        If I change the first 4 lines to

        package Text::CSV_XS; # Copyright (c)2007-2011 # H.Merijn Brand. All rights reserved. # Copyright (c)1998-2001 # Jochen Wiedmann. All rights reserved.

        I also pass this command on Windows/Strawberry. I could make that change, but does it help in the end? I mean, the IO bug is still luring in the backyard.


        Enjoy, Have FUN! H.Merijn

        OK, I converted the text file named CSV_XS.pm from Unix format to DOS format (that is, I added CR characters to it).

        C:\>perldoc -l Text::CSV_XS C:\strawberry\perl\site\lib\Text\CSV_XS.pm C:\>chdir C:\strawberry\perl\site\lib\Text\ C:\strawberry\perl\site\lib\Text>bytecnt < CSV_XS.pm | egrep "CR|LF" 10 0A LF 1938 13 0D CR 0 C:\strawberry\perl\site\lib\Text>attrib CSV_XS.pm A R C:\strawberry\perl\site\lib\Text\CSV_XS.pm C:\strawberry\perl\site\lib\Text>attrib -r CSV_XS.pm C:\strawberry\perl\site\lib\Text>rename CSV_XS.pm CSV_XS.pm_LF_Only C:\strawberry\perl\site\lib\Text>sed -n p CSV_XS.pm_LF_Only > CSV_XS.p +m C:\strawberry\perl\site\lib\Text>attrib +r CSV_XS.pm C:\strawberry\perl\site\lib\Text>bytecnt < CSV_XS.pm | egrep "CR|LF" 10 0A LF 1938 13 0D CR 1938 C:\strawberry\perl\site\lib\Text>wc -l CSV_XS.pm 1938 CSV_XS.pm C:\strawberry\perl\site\lib\Text>

        Then I tested it. It resolved the problem.

        C:\>perl -Mopen=:encoding(UTF-8) -MText::CSV_XS -e 1 C:\>perl -MText::CSV_XS -Mopen=:encoding(UTF-8) -e 1 C:\>

        Thank you, ikegami and Tux.

        Jim