in reply to What does \1 do?

Using a backslash "escapes" the following character. Given:

$n = "\1n\1r"; foreach (split //, $n) { print ++$x." ".ord($_)."\n"; }

...produces:

11
2110
31
4114

Check out Quote and Quote-like Operators in perlop.

Replies are listed 'Best First'.
Re: Re: What does \1 do?
by hv (Prior) on May 10, 2003 at 12:56 UTC
    Using a backslash "escapes" the following character.

    That's not entirely true in this case: if the first character following a backslash is a digit [0-7], the sequence of up to 3 octal digits following is the escape sequence, and the resulting octal number is converted to the character with that index:

    perl -wle '$s = "\100"; print ord($s)' 64

    Similarly, "\x" introduces a sequence of up to 2 hex digits, eg "\x3f". In Unicode-aware perls (perl-5.6.0 and later) you can also introduce codepoints above 255 by putting braces around the hex number:

    perl -wle '$s = "\x{1000}"; print ord($s)' 4096

    Hugo