in reply to detecting carraige returns

A carriage return is "\r" or "\x0d" in a regex, so either of the following would work:
/\r/ /\x0d/

Replies are listed 'Best First'.
Re: Re: detecting carraige returns
by etcshadow (Priest) on Dec 07, 2003 at 07:33 UTC
    ...And I'm not saying this to dis on the guy... but if he doesn't know how to write a regex to "detect a carriage return", he might not know about the subtleties of the various characters in the big bag known as "return".

    "Carriage return" is "\r". It is the control character which actually means to move your cursor (or the carriage on your typewriter/tty) over to the far left margin.

    "Line feed Newline" (which might be what you meant but didn't know you meant) is "\n". It is the control character which means to move your cursor (or, etc.) down one line.

    To make matters worse, different operating systems have different ideas of what the "Enter" key on your keyboard means and/or what character separates lines in a text file. DOS/Windows, being overly literal, expects both... one to go down a line and one to go back to the left margin "\r\n". Unix, is happy with just the line feed newline (no carriage return) "\n". And MAC, just to be different wants a carriage return (but no line feed newline) "\r". However, just to add to the confusion, different languages/platforms may map all of these combinations to and from a simple "\n" as appropos of the operating system.

    Anyway, I just point this out because even though what you asked for was /\r/... it could be that what you need is /\r\n/ or, more likely, /\n/.

    Update: as duff points out, I meant to say line feed (referring to the specific control character by name), but said newline instead. Should have man'd ascii quickly before posting so I didn't reverse the terms. My bad.


    ------------
    :Wq
    Not an editor command: Wq
      "Newline" (which might be what you meant but didn't know you meant) is "\n". It is the control character which means to move your cursor (or, etc.) down one line.

      Er, not quite. "Newline" is a sequence of characters that signify the end of one logical line and the beginning of another. That sequence is represented by "\n" in perl. The character that means "move your cursor to the next line" is a line feed which is ASCII ordinal 10. (Often you will see it represented in hexadecimal (x0A) or octal (012)) See the section on newlines in perlport

      What you say about "Enter" is essentially what is true about "\n". Just replace everywhere you have "\n" with "\012" or "\x0A" or even the text "line feed character".