develooper Front page | perl.perl5.porters | Postings from August 2010

Re: Any opposition still to the idea of syntax indicating defaultregex modifiers?

Thread Previous | Thread Next
karl williamson
August 11, 2010 09:44
Re: Any opposition still to the idea of syntax indicating defaultregex modifiers?
Message ID:
demerphq wrote:
> On 10 August 2010 23:32, karl williamson <> wrote:
>> If we're going to do this, I'd like to do it now before the new regex
>> modifiers go in.
>> Aristotle withdrew his opposition and became a supporter after he understood
>> what the proposal really was.  Sorry for being unclear.
>> If there's no opposition, we need to settle on what is the syntax is. Ben
>> originally proposed (?~  I thought (?.  was better because the tilde can be
>> too easily confused with a hyphen, (?-  which is also legal right after the
>> question mark.
>> Another option is to make it a two character sequence, the first one is a
>> tilde, say, and I'm not sure what the second one should be.  This would
>> allow future expansion so that some other 2nd char could mean something
>> else.  Mostly people wouldn't type this, it would be inserted by the regex
>> compiler.
> Karl can you present this to us as it might be documented in perlre?
> Im still having a hard time grokking this one....
> Yves

Here is an initial stab at it, using a period for the character:

diff --git a/pod/perlre.pod b/pod/perlre.pod
index 98aafdd..40bae6c 100644
--- a/pod/perlre.pod
+++ b/pod/perlre.pod
@@ -636,6 +636,8 @@ X<(?:)>

  =item C<(?imsx-imsx:pattern)>

+=item C<(?.imsx-imsx:pattern)>
  This is for clustering, not capturing; it groups subexpressions like
  "()", but doesn't make backreferences as "()" does.  So

@@ -657,6 +659,33 @@ is equivalent to the more verbose


+Starting in Perl 5.14, a C<.> (dot) immediately after the C<?> is a
+shorthand equivalent to C<-imsx>.  Any positive or negative flags may
+follow the dot, so
+    (?.x-i:foo)
+is equivalent to
+    (?x-ims:foo)
+(The C<-i> wasn't necessary, but did no harm.)
+The dot tells Perl that this cluster doesn't inherit the flags of any
+surrounding pattern, but to go back to the system defaults (C<-imsx>),
+modified by any flags specified.
+The dot allows for simpler stringification of compiled regular
+expressions.  These look like
+    (?.:pattern)
+with any non-default flags appearing between the dot and the colon.
+A test that looks at such stringification thus doesn't need to have the
+system default flags hard-coded in it, just the dot.  If new flags are
+added to Perl, the meaning of the dot's expansion will change to include
+the default for those flags, so the test will still work, unchanged.
  =item C<(?|pattern)>
  X<(?|)> X<Branch reset>

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About