From 4f33871e476d22c53497f8752b4846aecb7d661a Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sat, 7 Nov 2020 12:18:26 -0700 Subject: [PATCH] perlop: Clarify parts of tr/// --- pod/perlop.pod | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/pod/perlop.pod b/pod/perlop.pod index 51303be3a2a2..7778b8222ca2 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -2595,25 +2595,36 @@ C. If the I is delimited by bracketing quotes, the I must have its own pair of quotes, which may or may -not be bracketing quotes; for example, C or -C. - -Characters may be literals, or (if the delimiters aren't single quotes) -any of the escape sequences accepted in double-quoted strings. But -there is never any variable interpolation, so C<"$"> and C<"@"> are -always treated as literals. A hyphen at the beginning or end, or -preceded by a backslash is also always considered a literal. Escape -sequence details are in L or +C. This final example shows a way to visually clarify +what is going on for people who are more familiar with regular +expression patterns than with C, and who may think forward slash +delimiters imply that C is more like a regular expression pattern +than it actually is. (Another option might be to use C.) + +C isn't fully like bracketed character classes, just +(significantly) more like them than it is to full patterns. For +example, characters appearing more than once in either list behave +differently here than in patterns, and C lists do not allow +backslashed character classes such as C<\d> or C<\pL>, nor variable +interpolation, so C<"$"> and C<"@"> are always treated as literals. + +What is allowed are literals, or (if the delimiters aren't single +quotes) any of the escape sequences accepted in double-quoted strings. +Escape sequence details are in L. -Note that C does B do regular expression character classes such as -C<\d> or C<\pL>. The C operator is not equivalent to the C> -utility. C will uppercase the 26 letters "a" through "z", -but for case changing not confined to ASCII, use -L|perlfunc/lc>, L|perlfunc/uc>, -L|perlfunc/lcfirst>, L|perlfunc/ucfirst> -(all documented in L), or the -LIEIE>|/sEPATTERNEREPLACEMENTEmsixpodualngcer> +A hyphen at the beginning or end, or preceded by a backslash is also +always considered a literal. Precede a delimiter character with a +backslash to allow it. + +The C operator is not equivalent to the C> utility. +C will uppercase the 26 letters "a" through "z", but for +case changing not confined to ASCII, use L|perlfunc/lc>, +L|perlfunc/uc>, L|perlfunc/lcfirst>, +L|perlfunc/ucfirst> (all documented in L), or the +LIEIE>|/sEPATTERNEREPLACEMENTEmsixpodualngcer> (with C<\U>, C<\u>, C<\L>, and C<\l> string-interpolation escapes in the I portion).