I'm revisiting line endings on both Windows and Linux, and found something that I'm not sure whether it's a bug or if I've overlooked something.

This is in relation to the \R match character in perlrebackslash.

Using this code (note that win.txt is definitely a Windows-ending file):

perl -nE '/(\R)/; say (unpack "H*", $1);' win.txt

...on many variants of Unix, produces:

0d0a

...which I expect. However, on Windows, it prints:

0a

...on literally the exact same file. In fact, I've even set up a VirtualBox shared directory between a Windows VM and a Linux host, and put the file there, as well as testing on a copy. The results are the same.

I've tested perl v5.18 and 5.22 on nix, and Strawberry v5.22 on Windows.

Shouldn't Windows perl also print 0d0a or am I missing something? If this isn't the correct behaviour, could I get one of our Monks who use ActiveState perl test as well?

Update: note that interestingly, I get the same result (0a on win and 0d0a on nix) when I change the regex to /(\s+$)/, so if this is a problem, it isn't only related to \R. Also, on Windows, /\r\n/ does match.


In reply to \R not working as (I'd have) expected on Windows Strawberry perl by stevieb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.