This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlrecharclass: Update regex sets pod
[perl5.git] / pod / perlrecharclass.pod
index 0089c5a..a2df2df 100644 (file)
@@ -1181,46 +1181,29 @@ closing C<])> characters.
 
 Just as in all regular expressions, the pattern can be built up by
 including variables that are interpolated at regex compilation time.
-But its best to compile each sub-component.
+But currently each such sub-component should be an already-compiled
+extended bracketed character class.
 
  my $thai_or_lao = qr/(?[ \p{Thai} + \p{Lao} ])/;
- my $lower = qr/(?[ \p{Lower} + \p{Digit} ])/;
+ ...
+ qr/(?[ \p{Digit} & $thai_or_lao ])/;
 
-When these are embedded in another pattern, what they match does not
-change, regardless of parenthesization or what modifiers are in effect
-in that outer pattern.  If you fail to compile the subcomponents, you
-can get some nasty surprises.  For example:
+If you interpolate something else, the pattern may still compile (or it
+may die), but if it compiles, it very well may not behave as you would
+expect:
 
  my $thai_or_lao = '\p{Thai} + \p{Lao}';
- ...
  qr/(?[ \p{Digit} & $thai_or_lao ])/;
 
 compiles to
 
  qr/(?[ \p{Digit} & \p{Thai} + \p{Lao} ])/;
 
-But this does not have the effect that someone reading the source code
+This does not have the effect that someone reading the source code
 would likely expect, as the intersection applies just to C<\p{Thai}>,
-excluding the Laotian.  Its best to compile the subcomponents, but you
-could also parenthesize the component pieces:
-
- my $thai_or_lao = '( \p{Thai} + \p{Lao} )';
-
-But any modifiers will still apply to all the components:
-
- my $lower = '\p{Lower} + \p{Digit}';
- qr/(?[ \p{Greek} & $lower ])/i;
-
-matches upper case things.  So just, compile the subcomponents, as
-illustrated above.
+excluding the Laotian.
 
 Due to the way that Perl parses things, your parentheses and brackets
 may need to be balanced, even including comments.  If you run into any
 examples, please submit them to L<https://github.com/Perl/perl5/issues>,
 so that we can have a concrete example for this man page.
-
-We may change it so that things that remain legal uses in normal bracketed
-character classes might become illegal within this experimental
-construct.  One proposal, for example, is to forbid adjacent uses of the
-same character, as in C<(?[ [aa] ])>.  The motivation for such a change
-is that this usage is likely a typo, as the second "a" adds nothing.