With non-alphabetical characters, the result is based on the 4 least-significant
bits of the input character, i.e., on C<ord($char)%16>. In particular,
characters C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes
-C<"\0"> and C<"\1">. For characters C<"a".."f"> and C<"A".."F">, the result
+C<"\000"> and C<"\001">. For characters C<"a".."f"> and C<"A".."F">, the result
is compatible with the usual hexadecimal digits, so that C<"a"> and
C<"A"> both generate the nybble C<0xa==10>. Do not use any characters
but these with this format.
# $foo = pack("WWWW",193,194,195,196);
$foo = pack("s2",1,2);
- # "\1\0\2\0" on little-endian
- # "\0\1\0\2" on big-endian
+ # "\001\000\002\000" on little-endian
+ # "\000\001\000\002" on big-endian
$foo = pack("a4","abcd","x","y","z");
# "abcd"
Some simple tricks for determining if you are running on an EBCDIC
platform could include any of the following (perhaps all):
- if ("\t" eq "\05") { print "EBCDIC may be spoken here!\n"; }
+ if ("\t" eq "\005") { print "EBCDIC may be spoken here!\n"; }
if (ord('A') == 193) { print "EBCDIC may be spoken here!\n"; }
=head3 Octal escapes
-Octal escapes consist of a backslash followed by two or three octal digits
-matching the code point of the character you want to use. This allows for
-512 characters (C<\00> up to C<\777>) that can be expressed this way (but
-anything above C<\377> is deprecated).
-Enough in pre-Unicode days, but most Unicode characters cannot be escaped
-this way.
+Octal escapes consist of a backslash followed by three octal digits
+matching the code point of the character you want to use. (In some contexts,
+two or even one octal digits are also accepted, sometimes with a warning.) This
+allows for 512 characters (C<\000> up to C<\777>) that can be expressed this
+way (but anything above C<\377> is deprecated). Enough in pre-Unicode days,
+but most Unicode characters cannot be escaped this way.
Note that a character that is expressed as an octal escape is considered
as a character without special meaning by the regex engine, and will match
Octal escapes potentially clash with old-style backreferences (see L</Absolute
referencing> below). They both consist of a backslash followed by numbers. So
Perl has to use heuristics to determine whether it is a backreference or an
-octal escape. Perl uses the following rules:
+octal escape. You can avoid ambiguity by using the C<\g> form for
+backreferences, and by beginning octal escapes with a "0". (Since octal
+escapes are 3 digits, this latter method works only up to C<\077>.) In the
+absence of C<\g>, Perl uses the following rules:
=over 4