suppress bogus warning on C<sub x {} x()>
[p5sagit/p5-mst-13.2.git] / pod / perlop.pod
index d9cfccf..35f9e5f 100644 (file)
@@ -187,10 +187,7 @@ operands C<$a> and C<$b>: If C<$b> is positive, then C<$a % $b> is
 C<$a> minus the largest multiple of C<$b> that is not greater than
 C<$a>.  If C<$b> is negative, then C<$a % $b> is C<$a> minus the
 smallest multiple of C<$b> that is not less than C<$a> (i.e. the
-result will be less than or equal to zero).  If C<use integer> is
-in effect, the native hardware will be used instead of this rule,
-which may be construed a bug that will be fixed at some point.
-
+result will be less than or equal to zero). 
 Note than when C<use integer> is in scope, "%" give you direct access
 to the modulus operator as implemented by your C compiler.  This
 operator is not as well defined for negative operands, but it will
@@ -639,7 +636,7 @@ next line. This allows you to write:
 
 For constructs that do interpolation, variables beginning with "C<$>"
 or "C<@>" are interpolated, as are the following sequences. Within
-a transliteration, the first ten of these sequences may be used.
+a transliteration, the first eleven of these sequences may be used.
 
     \t         tab             (HT, TAB)
     \n         newline         (NL)
@@ -648,8 +645,9 @@ a transliteration, the first ten of these sequences may be used.
     \b         backspace       (BS)
     \a         alarm (bell)    (BEL)
     \e         escape          (ESC)
-    \033       octal char
-    \x1b       hex char
+    \033       octal char      (ESC)
+    \x1b       hex char        (ESC)
+    \x{263a}   wide hex char   (SMILEY)
     \c[                control char
 
     \l         lowercase next char
@@ -777,11 +775,11 @@ I<successfully> matched regular expression is used instead.
 
 If the C</g> option is not used, C<m//> in a list context returns a
 list consisting of the subexpressions matched by the parentheses in the
-pattern, i.e., (C<$1>, C<$2>, C<$3>...).  (Note that here
-C<$1> etc. are also set, and
-that this differs from Perl 4's behavior.)  If there are no parentheses,
-the return value is the list C<(1)> for success or C<('')> upon failure.
-With parentheses, C<()> is returned upon failure.
+pattern, i.e., (C<$1>, C<$2>, C<$3>...).  (Note that here C<$1> etc. are
+also set, and that this differs from Perl 4's behavior.)  When there are
+no parentheses in the pattern, the return value is the list C<(1)> for
+success.  With or without parentheses, an empty list is returned upon
+failure.
 
 Examples:
 
@@ -916,7 +914,8 @@ A string which is (possibly) interpolated and then compiled as a
 regular expression. The result may be used as a pattern in a match
 
     $re = qr/$pattern/;
-    $string =~ /$re/;
+    $string =~ /foo${re}bar/;  # can be interpolated in other patterns
+    $string =~ $re;            # or used standalone
 
 Options are:
 
@@ -926,8 +925,9 @@ Options are:
     s  Treat string as single line.
     x  Use extended regular expressions.
 
-The benefit from this is that the pattern is compiled into an internal
-representation by the C<qr//> operator and not by the match operator.
+The benefit from this is that the pattern is precompiled into an internal
+representation, and does not need to be recompiled every time a match
+is attempted.  This makes it very efficient to do something like:
 
     foreach $pattern (@pattern_list) {
        my $re = qr/$pattern/;
@@ -938,6 +938,9 @@ representation by the C<qr//> operator and not by the match operator.
        }
     }
 
+See L<perlre> for additional information on valid syntax for STRING, and
+for a detailed look at the semantics of regular expressions.
+
 =item qx/STRING/
 
 =item `STRING`
@@ -1136,9 +1139,9 @@ to occur.  Here are two common cases:
     1 while s/\t+/' ' x (length($&)*8 - length($`)%8)/e;
 
 
-=item tr/SEARCHLIST/REPLACEMENTLIST/cds
+=item tr/SEARCHLIST/REPLACEMENTLIST/cdsUC
 
-=item y/SEARCHLIST/REPLACEMENTLIST/cds
+=item y/SEARCHLIST/REPLACEMENTLIST/cdsUC
 
 Transliterates all occurrences of the characters found in the search list
 with the corresponding character in the replacement list.  It returns
@@ -1158,6 +1161,8 @@ Options:
     c  Complement the SEARCHLIST.
     d  Delete found but unreplaced characters.
     s  Squash duplicate replaced characters.
+    U  Translate to/from UTF-8.
+    C  Translate to/from 8-bit char (octet).
 
 If the C</c> modifier is specified, the SEARCHLIST character set is
 complemented.  If the C</d> modifier is specified, any characters specified
@@ -1175,6 +1180,10 @@ enough.  If the REPLACEMENTLIST is empty, the SEARCHLIST is replicated.
 This latter is useful for counting characters in a class or for
 squashing character sequences in a class.
 
+The first C</U> or C</C> modifier applies to the left side of the translation.
+The second one applies to the right side.  If present, these modifiers override
+the current utf8 state.
+
 Examples:
 
     $ARGV[1] =~ tr/A-Z/a-z/;   # canonicalize to lower case
@@ -1194,6 +1203,9 @@ Examples:
     tr [\200-\377]
        [\000-\177];            # delete 8th bit
 
+    tr/\0-\xFF//CU;            # translate Latin-1 to Unicode
+    tr/\0-\x{FF}//UC;          # translate Unicode to Latin-1
+
 If multiple transliterations are given for a character, only the first one is used:
 
     tr/AAA/XYZ/
@@ -1238,7 +1250,7 @@ one to five, but they are always performed in the same order.
 
 First pass is finding the end of the quoted construct, be it multichar ender
 C<"\nEOF\n"> of C<<<EOF> construct, C</> which terminates C<qq/> construct,
-C<E<]>> which terminates C<qq[> construct, or C<E<gt>> which terminates a
+C<]> which terminates C<qq[> construct, or C<E<gt>> which terminates a
 fileglob started with C<<>.
 
 When searching for multichar construct no skipping is performed.  When 
@@ -1247,9 +1259,9 @@ C<\\> and C<\/> are skipped.  When searching for one-char matching delimiter,
 such as C<]>, combinations C<\\>, C<\]> and C<\[> are skipped, and 
 nested C<[>, C<]> are skipped as well.
 
-For 3-parts constructs C<s///> etc. the search is repeated once more.
+For 3-parts constructs, C<s///> etc. the search is repeated once more.
 
-During this search no attension is paid to the semantic of the construct, thus
+During this search no attention is paid to the semantic of the construct, thus
 
     "$hash{"$foo/$bar"}"
 
@@ -1280,7 +1292,7 @@ parsing.
 =item Interpolation
 
 Next step is interpolation in the obtained delimiter-independent text.
-There are many different cases.
+There are four different cases.
 
 =over
 
@@ -1310,11 +1322,11 @@ constructs, thus C<"'@arr'"> becomes
 Since all three above steps are performed simultaneously left-to-right,
 the is no way to insert a literal C<$> or C<@> inside C<\Q\E> pair: it
 cannot be protected by C<\>, since any C<\> (except in C<\E>) is 
-interpreted as a literal inside C<\Q\E>, and any $ is 
+interpreted as a literal inside C<\Q\E>, and any C<$> is 
 interpreted as starting an interpolated scalar.
 
 Note also that the interpolating code needs to make decision where the 
-interpolated scalar ends, say, whether C<"a $b -> {c}"> means 
+interpolated scalar ends, say, whether C<"a $b -E<gt> {c}"> means 
 
   "a " . $b . " -> {c}";
 
@@ -1328,24 +1340,24 @@ not include spaces between components and contains matching braces/brackets.
 =item C<?RE?>, C</RE/>, C<m/RE/>, C<s/RE/foo/>, 
 
 Processing of C<\Q>, C<\U>, C<\u>, C<\L>, C<\l> and interpolation happens 
-(almost) as with qq// constructs, but I<the substitution of C<\> followed by
+(almost) as with C<qq//> constructs, but I<the substitution of C<\> followed by
 other chars is not performed>!  Moreover, inside C<(?{BLOCK})> no processing
 is performed at all.
 
-Interpolation has several quirks: $|, $( and $) are not interpolated, and
+Interpolation has several quirks: C<$|>, C<$(> and C<$)> are not interpolated, and
 constructs C<$var[SOMETHING]> are I<voted> (by several different estimators) 
-to be an array element or $var followed by a RE alternative.  This is
+to be an array element or C<$var> followed by a RE alternative.  This is
 the place where the notation C<${arr[$bar]}> comes handy: C</${arr[0-9]}/>
-is interpreted as an array element -9, not as a regular expression from
-variable $arr followed by a digit, which is the interpretation of 
+is interpreted as an array element C<-9>, not as a regular expression from
+variable C<$arr> followed by a digit, which is the interpretation of 
 C</$arr[0-9]/>.
 
-Note that absense of processing of C<\\> creates specific restrictions on the
-post-processed text: if the delimeter is C</>, one cannot get the combination
+Note that absence of processing of C<\\> creates specific restrictions on the
+post-processed text: if the delimiter is C</>, one cannot get the combination
 C<\/> into the result of this step: C</> will finish the regular expression,
 C<\/> will be stripped to C</> on the previous step, and C<\\/> will be left
 as is.  Since C</> is equivalent to C<\/> inside a regular expression, this
-does not matter unless the delimiter is special character for RE engine, as 
+does not matter unless the delimiter is special character for the RE engine, as 
 in C<s*foo*bar*>, C<m[foo]>, or C<?foo?>.
 
 =back
@@ -1359,19 +1371,19 @@ All the previous steps were performed during the compilation of Perl code,
 this one happens in run time (though it may be optimized to be calculated
 at compile time if appropriate).  After all the preprocessing performed 
 above (and possibly after evaluation if catenation, joining, up/down-casing 
-and quotemeta()ing are involved) the resulting I<string> is passed to RE
+and C<quotemeta()>ing are involved) the resulting I<string> is passed to RE
 engine for compilation.
 
 Whatever happens in the RE engine is better be discussed in L<perlre>,
 but for the sake of continuity let us do it here.
 
-This is the first step where presense of the C<//x> switch is relevant.
-RE engine scans the string left-to-right, and converts it to a finite 
+This is the first step where presence of the C<//x> switch is relevant.
+The RE engine scans the string left-to-right, and converts it to a finite 
 automaton.  
 
 Backslashed chars are either substituted by corresponding literal 
 strings, or generate special nodes of the finite automaton.  Characters
-which are special to RE engine generate corresponding nodes.  C<(?#...)>
+which are special to the RE engine generate corresponding nodes.  C<(?#...)>
 comments are ignored.  All the rest is either converted to literal strings
 to match, or is ignored (as is whitespace and C<#>-style comments if
 C<//x> is present).
@@ -1382,7 +1394,7 @@ Similarly, the C<(?{...})> is only checked for matching braces.
 
 =item Optimization of regular expressions
 
-This step is listed for compeleteness only.  Since it does not change
+This step is listed for completeness only.  Since it does not change
 semantics, details of this step are not documented and are subject
 to change.