Perl Escape Characters

Within a transliteration, the first ten of these sequences may be used.

    \t          tab             (HT, TAB)
    \n          newline         (NL) may not be carrage return + line feed.
    \r          return          (CR) may not be the ascii carrage return
    \f          form feed       (FF)
    \b          backspace       (BS)
    \a          alarm (bell)    (BEL)
    \e          escape          (ESC)
    \0oo        oo=octal ASCII char value e.g. form feed (\f) is \014
    \xhh        hh=hex ASCII char value e.g. form feed (\f) is \x0C
    \c[         [=control char e.g. form feed (\f) is \cL


    \l          lowercase next char
    \u          uppercase next char
    \L          lowercase till \E
    \U          uppercase till \E
    \E          end case modification
    \Q          quote non-word characters till \E

If use locale is in effect, the case map used by \l, \L, \u and \U is taken from the current locale. See the perllocale manpage.

All systems use the virtual "\n" to represent a line terminator, called a "newline''. There is no such thing as an unvarying, physical newline character. It is an illusion that the operating system, device drivers, C libraries, and Perl all conspire to preserve. Not all systems read "\r" as ASCII CR and "\n" as ASCII LF. For example, on a Mac, these are reversed, and on systems without line terminator, printing "\n" may emit no actual data. In general, use "\n" when you mean a ``newline'' for your system, but use the literal ASCII when you need an exact character. For example, most networking protocols expect and prefer a CR+LF ( "\012\015" or "\cJ\cM") for line terminators, and although they often accept just "\012", they seldom tolerate just "\015". If you get in the habit of using "\n" for networking, you may be burned some day.

 

Comments: