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
From:
Ben Morrow
Date:
August 15, 2010 10:13
Subject:
Re: Any opposition still to the idea of syntax indicating defaultregex modifiers?
Message ID:
20100815171339.GA16699@osiris.mauzo.dyndns.org
Quoth public@khwilliamson.com (karl williamson):
> Ronald J Kimball wrote:
> > On Sat, Aug 14, 2010 at 09:13:06AM +0100, Zefram wrote:
> >> Ronald J Kimball wrote:
> >>> my @options_on  = qw/ s a /;  # where a and b are hypothetical options
> >>> my @options_off = qw/ i b /;  # that are on by default
> >> No options are on by default.
> > 
> > I know that's the current state, but is that a guarantee going forwards?
> > If options will always be off by default, then we probably don't need
> > (?.m-i:) at all; (?.m) would be sufficient.  (And my objection to Ben's
> > proposal would be moot. :)
> > 
> > I note that Karl mentioned that the new regex modifiers - /l, /u, and /d -
> > are "automatically inserted" under the appropriate conditions.  I don't
> > know if that means they are "on by default" with regards to (?.)
> > 
> > Ronald
> > 
> 
> Yes, /d is on by default.

But there is never a need to turn it off explicitly: it's not a boolean
option, but a three-way choice. The way to turn it off is (?.l:foo) or
(?.u:foo), not (?.-d:foo).

I've mentioned in passing before, and I think I should say again, that
having a /d switch at all is rather confusing. IMHO it would be much
better (if we're going to restrict ourselves to one-letter switches with
no arguments) to just have /u and /l, with the old behaviour implied by
neither of those being present. The new (?.:) syntax would mean that the
one place where /d might potentially be used, (?d-xims:foo), is better
written (?.:foo).

If you're going to introduce pragmata to turn some switches on for some
lexical scopes, the question of 'so how do they get turned off again?'
needs to be addressed in a more systematic way than just introducing a
single special-case switch that turns some other switches off. I would
be happy with either of

    use unicode_strings;
    /foo/U;

or

    use unicode_strings;
    /foo/-u;

though the latter obviously has more back-compat considerations. I would
also be happy, for now, with requiring people write

    use unicode_strings;
    /(?-u)foo/;

if they want to go back to the old semantics.

While we're discussing this: would you be at all open to the idea of
supplying a /a ('ASCII') switch that makes \d\s\w match what everyone
thinks they do (that is, [0-9], [ \t\n] and [a-zA-Z0-9_] respectively)?

Ben


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About