This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove refs to bare ?RE? in pods
[perl5.git] / pod / perlop.pod
index 2640b51..26196c8 100644 (file)
@@ -217,8 +217,8 @@ are platform-dependent.
 =head2 Symbolic Unary Operators
 X<unary operator> X<operator, unary>
 
-Unary C<"!"> performs logical negation, that is, "not".  See also C<not> for a lower
-precedence version of this.
+Unary C<"!"> performs logical negation, that is, "not".  See also
+L<C<not>|/Logical Not> for a lower precedence version of this.
 X<!>
 
 Unary C<"-"> performs arithmetic negation if the operand is numeric,
@@ -404,7 +404,7 @@ If you get tired of being subject to your platform's native integers,
 the S<C<use bigint>> pragma neatly sidesteps the issue altogether:
 
     print 20 << 20;  # 20971520
-    print 20 << 40;  # 5120 on 32-bit machines, 
+    print 20 << 40;  # 5120 on 32-bit machines,
                      # 21990232555520 on 64-bit machines
     use bigint;
     print 20 << 100; # 25353012004564588029934064107520
@@ -449,7 +449,7 @@ See also L</"Terms and List Operators (Leftward)">.
 =head2 Relational Operators
 X<relational operator> X<operator, relational>
 
-Perl operators that return true or false generally return values 
+Perl operators that return true or false generally return values
 that can be safely used as numbers.  For example, the relational
 operators in this section and the equality operators in the next
 one return C<1> for true and a special version of the defined empty
@@ -579,81 +579,81 @@ whose types apply determines the smartmatch behavior.  Because what
 actually happens is mostly determined by the type of the second operand,
 the table is sorted on the right operand instead of on the left.
 
- Left      Right      Description and pseudocode                               
+ Left      Right      Description and pseudocode
  ===============================================================
- Any       undef      check whether Any is undefined                    
+ Any       undef      check whether Any is undefined
                 like: !defined Any
 
  Any       Object     invoke ~~ overloading on Object, or die
 
  Right operand is an ARRAY:
 
- Left      Right      Description and pseudocode                               
+ Left      Right      Description and pseudocode
  ===============================================================
  ARRAY1    ARRAY2     recurse on paired elements of ARRAY1 and ARRAY2[2]
                 like: (ARRAY1[0] ~~ ARRAY2[0])
                         && (ARRAY1[1] ~~ ARRAY2[1]) && ...
- HASH      ARRAY      any ARRAY elements exist as HASH keys             
+ HASH      ARRAY      any ARRAY elements exist as HASH keys
                 like: grep { exists HASH->{$_} } ARRAY
  Regexp    ARRAY      any ARRAY elements pattern match Regexp
                 like: grep { /Regexp/ } ARRAY
- undef     ARRAY      undef in ARRAY                                    
+ undef     ARRAY      undef in ARRAY
                 like: grep { !defined } ARRAY
- Any       ARRAY      smartmatch each ARRAY element[3]                   
+ Any       ARRAY      smartmatch each ARRAY element[3]
                 like: grep { Any ~~ $_ } ARRAY
 
  Right operand is a HASH:
 
- Left      Right      Description and pseudocode                               
+ Left      Right      Description and pseudocode
  ===============================================================
- HASH1     HASH2      all same keys in both HASHes                      
+ HASH1     HASH2      all same keys in both HASHes
                 like: keys HASH1 ==
                          grep { exists HASH2->{$_} } keys HASH1
- ARRAY     HASH       any ARRAY elements exist as HASH keys             
+ ARRAY     HASH       any ARRAY elements exist as HASH keys
                 like: grep { exists HASH->{$_} } ARRAY
- Regexp    HASH       any HASH keys pattern match Regexp                
+ Regexp    HASH       any HASH keys pattern match Regexp
                 like: grep { /Regexp/ } keys HASH
- undef     HASH       always false (undef can't be a key)               
+ undef     HASH       always false (undef can't be a key)
                 like: 0 == 1
- Any       HASH       HASH key existence                                
+ Any       HASH       HASH key existence
                 like: exists HASH->{Any}
 
  Right operand is CODE:
 
- Left      Right      Description and pseudocode                               
+ Left      Right      Description and pseudocode
  ===============================================================
  ARRAY     CODE       sub returns true on all ARRAY elements[1]
                 like: !grep { !CODE->($_) } ARRAY
  HASH      CODE       sub returns true on all HASH keys[1]
                 like: !grep { !CODE->($_) } keys HASH
- Any       CODE       sub passed Any returns true              
+ Any       CODE       sub passed Any returns true
                 like: CODE->(Any)
 
 Right operand is a Regexp:
 
- Left      Right      Description and pseudocode                               
+ Left      Right      Description and pseudocode
  ===============================================================
- ARRAY     Regexp     any ARRAY elements match Regexp                   
+ ARRAY     Regexp     any ARRAY elements match Regexp
                 like: grep { /Regexp/ } ARRAY
- HASH      Regexp     any HASH keys match Regexp                        
+ HASH      Regexp     any HASH keys match Regexp
                 like: grep { /Regexp/ } keys HASH
- Any       Regexp     pattern match                                     
+ Any       Regexp     pattern match
                 like: Any =~ /Regexp/
 
  Other:
 
- Left      Right      Description and pseudocode                               
+ Left      Right      Description and pseudocode
  ===============================================================
  Object    Any        invoke ~~ overloading on Object,
                       or fall back to...
 
- Any       Num        numeric equality                                  
+ Any       Num        numeric equality
                  like: Any == Num
  Num       nummy[4]    numeric equality
                  like: Num == nummy
  undef     Any        check whether undefined
                  like: !defined(Any)
- Any       Any        string equality                                   
+ Any       Any        string equality
                  like: Any eq Any
 
 
@@ -662,13 +662,13 @@ Notes:
 =over
 
 =item 1.
-Empty hashes or arrays match. 
+Empty hashes or arrays match.
 
 =item 2.
 That is, each element smartmatches the element of the same index in the other array.[3]
 
 =item 3.
-If a circular reference is found, fall back to referential equality. 
+If a circular reference is found, fall back to referential equality.
 
 =item 4.
 Either an actual number, or a string that looks like one.
@@ -723,7 +723,7 @@ recursively.
     my @bigger = ("red", "blue", [ "orange", "green" ] );
     if (@little ~~ @bigger) {  # true!
         say "little is contained in bigger";
-    } 
+    }
 
 Because the smartmatch operator recurses on nested arrays, this
 will still report that "red" is in the array.
@@ -737,21 +737,21 @@ If two arrays smartmatch each other, then they are deep
 copies of each others' values, as this example reports:
 
     use v5.12.0;
-    my @a = (0, 1, 2, [3, [4, 5], 6], 7); 
-    my @b = (0, 1, 2, [3, [4, 5], 6], 7); 
+    my @a = (0, 1, 2, [3, [4, 5], 6], 7);
+    my @b = (0, 1, 2, [3, [4, 5], 6], 7);
 
     if (@a ~~ @b && @b ~~ @a) {
         say "a and b are deep copies of each other";
-    } 
+    }
     elsif (@a ~~ @b) {
         say "a smartmatches in b";
-    } 
+    }
     elsif (@b ~~ @a) {
         say "b smartmatches in a";
-    } 
+    }
     else {
         say "a and b don't smartmatch each other at all";
-    } 
+    }
 
 
 If you were to set S<C<$b[3] = 4>>, then instead of reporting that "a and b
@@ -818,7 +818,7 @@ C<I<X>>, overloading may or may not be invoked.  For simple strings or
 numbers, "in" becomes equivalent to this:
 
     $object ~~ $number          ref($object) == $number
-    $object ~~ $string          ref($object) eq $string 
+    $object ~~ $string          ref($object) eq $string
 
 For example, this reports that the handle smells IOish
 (but please don't really do this!):
@@ -827,7 +827,7 @@ For example, this reports that the handle smells IOish
     my $fh = IO::Handle->new();
     if ($fh ~~ /\bIO\b/) {
         say "handle smells IOish";
-    } 
+    }
 
 That's because it treats C<$fh> as a string like
 C<"IO::Handle=GLOB(0x8039e0)">, then pattern matches against that.
@@ -940,7 +940,7 @@ It would be even more readable to write that this way:
     unless(unlink("alpha", "beta", "gamma")) {
         gripe();
         next LINE;
-    } 
+    }
 
 Using C<"or"> for assignment is unlikely to do what you want; see below.
 
@@ -1074,6 +1074,12 @@ If the final value specified is not in the sequence that the magical
 increment would produce, the sequence goes until the next value would
 be longer than the final value specified.
 
+As of Perl 5.26, the list-context range operator on strings works as expected
+in the scope of L<< S<C<"use feature 'unicode_strings">>|feature/The
+'unicode_strings' feature >>. In previous versions, and outside the scope of
+that feature, it exhibits L<perlunicode/The "Unicode Bug">: its behavior
+depends on the internal encoding of the range endpoint.
+
 If the initial value specified isn't part of a magical increment
 sequence (that is, a non-empty string matching C</^[a-zA-Z]*[0-9]*\z/>),
 only the initial value will be returned.  So the following will only
@@ -1086,9 +1092,9 @@ To get the 25 traditional lowercase Greek letters, including both sigmas,
 you could use this instead:
 
     use charnames "greek";
-    my @greek_small =  map { chr } ( ord("\N{alpha}") 
+    my @greek_small =  map { chr } ( ord("\N{alpha}")
                                         ..
-                                     ord("\N{omega}") 
+                                     ord("\N{omega}")
                                    );
 
 However, because there are I<many> other lowercase Greek characters than
@@ -1262,16 +1268,19 @@ The only operators with lower precedence are the logical operators
 C<"and">, C<"or">, and C<"not">, which may be used to evaluate calls to list
 operators without the need for parentheses:
 
-    open HANDLE, "< :utf8", "filename" or die "Can't open: $!\n";
+    open HANDLE, "< :encoding(UTF-8)", "filename"
+        or die "Can't open: $!\n";
 
 However, some people find that code harder to read than writing
 it with parentheses:
 
-    open(HANDLE, "< :utf8", "filename") or die "Can't open: $!\n";
+    open(HANDLE, "< :encoding(UTF-8)", "filename")
+        or die "Can't open: $!\n";
 
 in which case you might as well just use the more customary C<"||"> operator:
 
-    open(HANDLE, "< :utf8", "filename") || die "Can't open: $!\n";
+    open(HANDLE, "< :encoding(UTF-8)", "filename")
+        || die "Can't open: $!\n";
 
 See also discussion of list operators in L</Terms and List Operators (Leftward)>.
 
@@ -1563,12 +1572,9 @@ as a Unicode code point no matter what the native encoding is.  The name of the
 character in the 256th position (indexed by 0) in Unicode is
 C<LATIN CAPITAL LETTER A WITH MACRON>.
 
-There are a couple of exceptions to the above rule.  S<C<\N{U+I<hex number>}>> is
+An exception to the above rule is that S<C<\N{U+I<hex number>}>> is
 always interpreted as a Unicode code point, so that C<\N{U+0050}> is C<"P"> even
-on EBCDIC platforms.  And if C<S<L<use encoding|encoding>>> is in effect, the
-number is considered to be in that encoding, and is translated from that into
-the platform's native encoding if there is a corresponding native character;
-otherwise to Unicode.
+on EBCDIC platforms.
 
 =back
 
@@ -1688,7 +1694,7 @@ interpolation is done.  Returns a Perl value which may be used instead of the
 corresponding C</I<STRING>/msixpodualn> expression.  The returned value is a
 normalized version of the original pattern.  It magically differs from
 a string containing the same characters: C<ref(qr/x/)> returns "Regexp";
-however, dereferencing it is not well defined (you currently get the 
+however, dereferencing it is not well defined (you currently get the
 normalized version of the original pattern, but this may change).
 
 
@@ -1737,15 +1743,18 @@ Options (specified by the following modifiers) are:
     m  Treat string as multiple lines.
     s  Treat string as single line. (Make . match a newline)
     i  Do case-insensitive pattern matching.
-    x  Use extended regular expressions.
+    x   Use extended regular expressions; specifying two
+        x's means \t and the SPACE character are ignored within
+        square-bracketed character classes
     p  When matching preserve a copy of the matched string so
         that ${^PREMATCH}, ${^MATCH}, ${^POSTMATCH} will be
         defined (ignored starting in v5.20) as these are always
-        defined starting in that relese
+        defined starting in that release
     o  Compile pattern only once.
-    a   ASCII-restrict: Use ASCII for \d, \s, \w; specifying two
-        a's further restricts things to that that no ASCII
-        character will match a non-ASCII one under /i.
+    a   ASCII-restrict: Use ASCII for \d, \s, \w and [[:posix:]]
+        character classes; specifying two a's adds the further
+        restriction that no ASCII character will match a
+        non-ASCII one under /i.
     l   Use the current run-time locale's rules.
     u   Use Unicode rules.
     d   Use Unicode or native charset, as in 5.12 and earlier.
@@ -1866,7 +1875,7 @@ If the C</g> option is not used, C<m//> in list context returns a
 list consisting of the subexpressions matched by the parentheses in the
 pattern, that is, (C<$1>, C<$2>, C<$3>...)  (Note that here C<$1> etc. are
 also set).  When there are no parentheses in the pattern, the return
-value is the list C<(1)> for success.  
+value is the list C<(1)> for success.
 With or without parentheses, an empty list is returned upon failure.
 
 Examples:
@@ -2027,8 +2036,6 @@ Here is the output (split into several lines):
 =item C<m?I<PATTERN>?msixpodualngc>
 X<?> X<operator, match-once>
 
-=item C<?I<PATTERN>?msixpodualngc>
-
 This is just like the C<m/I<PATTERN>/> search, except that it matches
 only once between calls to the C<reset()> operator.  This is a useful
 optimization when you want to see only the first occurrence of
@@ -2286,7 +2293,7 @@ On some platforms (notably DOS-like ones), the shell may not be
 capable of dealing with multiline commands, so putting newlines in
 the string may not get you what you want.  You may be able to evaluate
 multiple commands in a single line by separating them with the command
-separator character, if your shell supports that (for example, C<;> on 
+separator character, if your shell supports that (for example, C<;> on
 many Unix shells and C<&> on the Windows NT C<cmd> shell).
 
 Perl will attempt to flush all files opened for
@@ -2782,7 +2789,7 @@ If the left part is delimited by bracketing punctuation (that is C<()>,
 C<[]>, C<{}>, or C<< <> >>), the right part needs another pair of
 delimiters such as C<s(){}> and C<tr[]//>.  In these cases, whitespace
 and comments are allowed between the two parts, although the comment must follow
-at least one whitespace character; otherwise a character expected as the 
+at least one whitespace character; otherwise a character expected as the
 start of the comment may be regarded as the starting delimiter of the right part.
 
 During this search no attention is paid to the semantics of the construct.
@@ -2905,7 +2912,7 @@ I<sed> hackers who haven't picked up the saner idiom yet.  A warning
 is emitted if the S<C<use warnings>> pragma or the B<-w> command-line flag
 (that is, the C<$^W> variable) was set.
 
-=item C<RE> in C<?RE?>, C</RE/>, C<m/RE/>, C<s/RE/foo/>,
+=item C<RE> in C<m?RE?>, C</RE/>, C<m/RE/>, C<s/RE/foo/>,
 
 Processing of C<\Q>, C<\U>, C<\u>, C<\L>, C<\l>, C<\F>, C<\E>,
 and interpolation happens (almost) as with C<qq//> constructs.
@@ -2948,7 +2955,7 @@ finish the regular expression, C<\/> will be stripped to C</> on
 the previous step, and C<\\/> will be left as is.  Because C</> is
 equivalent to C<\/> inside a regular expression, this does not
 matter unless the delimiter happens to be character special to the
-RE engine, such as in C<s*foo*bar*>, C<m[foo]>, or C<?foo?>; or an
+RE engine, such as in C<s*foo*bar*>, C<m[foo]>, or C<m?foo?>; or an
 alphanumeric char, as in:
 
   m m ^ a \s* b mmx;
@@ -3069,7 +3076,7 @@ The following lines are equivalent:
     print while ($_ = <STDIN>);
     print while <STDIN>;
 
-This also behaves similarly, but assigns to a lexical variable 
+This also behaves similarly, but assigns to a lexical variable
 instead of to C<$_>:
 
     while (my $line = <STDIN>) { print $line }
@@ -3276,7 +3283,7 @@ variable substitution.  Backslash interpolation also happens at
 compile time.  You can say
 
       'Now is the time for all'
-    . "\n" 
+    . "\n"
     .  'good men to come to.'
 
 and this all reduces to one string internally.  Likewise, if