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
Ben Morrow
August 13, 2010 12:21
Re: Any opposition still to the idea of syntax indicating defaultregex modifiers?
Message ID:
Quoth (Ronald J Kimball):
> On Fri, Aug 13, 2010 at 05:26:56AM +0100, Ben Morrow wrote:
> > 
> > I want it to not be valid syntax, just as though I'd written
> > 
> >     /(?.x!i:foo)/
> > 
> > or anything else invalid. I suppose that means 'error', but just an
> > ordinary 'Sequence not recognized in regex' error, not a special case.
> I don't agree with the justification for disallowing (?.-i: .
> Perhaps someone will want to emphasize that case insensitive matching is
> turned off in a certain case.

By the same token we should allow


just in case someone wants to 'emphasize' that fact there. I don't think
that's sensible.

> Perhaps someone will write a regex generator that allows the user to
> specify which options are on and which are off.  Disallowing (?.-i: means
> the program would have to keep track of which options were off by default.
> The program would also have to be updated each time a new option was added
> to the language.


(Is this really that hard to understand, or am I just explaining it

The syntax for 'turn some options on, turn some off, leave the rest as
they were outside this group' is (?s-ixm:), just as it has always been.
Noone is suggesting getting rid of that, or changing it in any way.

This new syntax is for pattern fragments that know exactly which flags
they want, regardless of what was in effect outside this group. A group

will match the same way as the stand-alone pattern


regardless of where you interpolate it. This will continue to apply
regardless of any new flags that are added later. This is exactly the
behaviour required by qr//.

The whole point is that you *don't* have to keep track of which flags
are off by default. Any flags you don't specify will be 'off', including
flags you don't know about because they haven't been added to perl yet.

> I don't think there's anything gained by disallowing the syntax, but there
> are things gained by allowing it.

Please give a concrete example of a situation where it would be useful.


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