http://www.perlmonks.org?node_id=939466


in reply to Re: crlf layer working on diamond operator, but not filehandle reads
in thread crlf layer working on diamond operator, but not filehandle reads

I know I let this thread die, but honestly I never figured out what was going on. Running the exact same code using perl -e and perl myprog.pl produced different results, and I never determined what was causing it.

However, I figured I should probably say what I ended up doing in case someone ever reads this with a similar problem. Setting :crlf as the current layer by use open IN => ":crlf" only seemed to work for files read by the empty diamond operator, and somehow broke for explicitly opened files, so I simply turned it off after the while(<>) loop with a no open IN => ":crlf", and explicitly added the layer to each file I opened (e.g. open(INFILE, "<:crlf", "myfile.csv")). This seems to always work, but only when the global layer isn't used.

Replies are listed 'Best First'.
Re^3: crlf layer working on diamond operator, but not filehandle reads
by ikegami (Patriarch) on Nov 23, 2011 at 01:40 UTC

    only seemed to work for files read by the empty diamond operator

    I proved otherwise.

      Your example did not work for me, and I am still unsure why. Output was Carriage return in myfile.csv at -e line 12, <INPUT> line 1. I was getting inconsistent results running it as perl -e '[BLOCK OF CODE]' myfile.csv and as perl code.pl myfile.csv. This was with Perl 5.10.1 running in Cygwin. I'm guessing it has something to do with Cygwin.

        I don't know how cygwin (which emulates a system that uses CRLF line endings) interacts with the rest of the system (which uses CRLF line endings). It is definitely a likely cause. My guess: It placed \r\r\n in the .csv.