SPUG: RE: One-liners on Windows via command.com

John W. Krahn krahnj at telus.net
Wed Mar 23 21:52:38 PST 2005


Aaron W. West wrote:
> Don't forget percent signs!
> 
> perldoc perlwin32 seems not to mention it:
> 
> In CMD.EXE or COMMAND.COM, percent signs in pairs are interpolated, when
> determined to be a valid *and existing* variable name.
> 
> It seems the solution is a backslash before the percent sign.
> 
> It also appears that in a perl command line \cm means control-M (CR), and
> \cj means control-J (LF). I don't know where this is documented.

perldoc perlop

        The following escape sequences are available in constructs that
        interpolate and in transliterations.

            \t          tab             (HT, TAB)
            \n          newline         (NL)
            \r          return          (CR)
            \f          form feed       (FF)
            \b          backspace       (BS)
            \a          alarm (bell)    (BEL)
            \e          escape          (ESC)
            \033        octal char      (ESC)
            \x1b        hex char        (ESC)
            \x{263a}    wide hex char   (SMILEY)
            \c[         control char    (ESC)
---------->^^
            \N{name}    named Unicode character

        NOTE: Unlike C and other languages, Perl has no \v escape sequence for
        the vertical tab (VT - ASCII 11).

        The following escape sequences are available in constructs that
        interpolate but not in transliterations.

            \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 perllocale.  If Unicode
        (for example, "\N{}" or wide hex characters of 0x100 or beyond) is
        being used, the case map used by "\l", "\L", "\u" and "\U" is as
        defined by Unicode.  For documentation of "\N{name}", see charnames.

        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 only 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 ("\015\012" or "\cM\cJ") 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.



John
-- 
use Perl;
program
fulfillment


More information about the spug-list mailing list