This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Prefer 3 digit octal character constants
authorKarl Williamson <khw@khw-desktop.(none)>
Tue, 22 Jun 2010 21:01:01 +0000 (15:01 -0600)
committerJesse Vincent <jesse@bestpractical.com>
Tue, 29 Jun 2010 02:30:05 +0000 (22:30 -0400)
By example and a few wording changes, show that 3 digit octal character
constants have less ambiguity.

pod/perlfunc.pod
pod/perlport.pod
pod/perlrebackslash.pod

index d528e2f..43a334d 100644 (file)
@@ -3880,7 +3880,7 @@ For each such format, pack() generates 4 bits of the result.
 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.
@@ -4204,8 +4204,8 @@ Examples:
     #      $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"
index 11ad8cd..ac260ed 100644 (file)
@@ -1277,7 +1277,7 @@ The values of C<$^O> on some of these platforms includes:
 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"; }
 
index 386622b..5728e7d 100644 (file)
@@ -207,12 +207,12 @@ match "as is".
 
 =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
@@ -230,7 +230,10 @@ 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