Front page | perl.perl5.porters |
Postings from February 2012
Re: [perl #109798] '/e' regexp modifier is not recognized by re pragma
Thread Previous
|
Thread Next
From:
demerphq
Date:
February 6, 2012 18:23
Subject:
Re: [perl #109798] '/e' regexp modifier is not recognized by re pragma
Message ID:
CANgJU+XYuaRa0YeVhLcL-km+KsfT0xqxQdw47k8F_WNUoy34Xw@mail.gmail.com
On 6 February 2012 20:48, Eric Brine <ikegami@adaelis.com> wrote:
> On Mon, Feb 6, 2012 at 5:42 AM, demerphq <demerphq@gmail.com> wrote:
>>
>> On 5 February 2012 23:12, Eric Brine <ikegami@adaelis.com> wrote:
>> > On Sun, Feb 5, 2012 at 12:22 PM, demerphq <demerphq@gmail.com> wrote:
>> >>
>> >> On 5 February 2012 01:19, Eric Brine via RT <perlbug-followup@perl.org>
>> >> wrote:
>> >> > On Sat Feb 04 16:15:49 2012, ikegami@adaelis.com wrote:
>> >> >> On Sat Feb 04 04:05:02 2012, glitchmr@myopera.com wrote:
>> >> >> > When '/e' modifier is used with 're' module, Perl complains about
>> >> >> > unknown modifier. Personally, I think that informing about '/e'
>> >> >> > not being able to be used by 're' module would be more useful.
>> >> >> >
>> >> >> > C:\Users\Konrad>perl -e "use re '/e'"
>> >> >> > Unknown regular expression flag "e" at -e line 1
>> >> >>
>> >> >> That message is accurate.
>> >> >>
>> >> >> >perl -e" /(?e:x)/ "
>> >> >> Sequence (?e...) not recognized in regex; marked by <-- HERE in
>> >> >> m/(?e
>> >> >> <-- HERE :x)/ at -e line 1.
>> >> >>
>> >> >> "e" is not a regular expression flag. It is a substitution operator
>> >> >> flag.
>> >> >
>> >> > Also note that "e" is not mentioned in perlre. The regex flags are
>> >> > (as
>> >> > listed in perlre): m, s, i, x, p, g, c, a, d, l, u.
>> >>
>> >> Just to note, perlre does not decide this. regexp.h does.
>> >>
>> >> > (I find this very odd that p, g and c are regex flags instead of
>> >> > match
>> >> > substitute operator flags, but they are are.)
>> >>
>> >> Huh?!
>> >>
>> >> /p relates to how we manage $`, $&, $', and has nothing to do with
>> >> substitution.
>> >>
>> >> /g relates to how match
>> >>
>> >> /c relates to how we match.
>> >>
>> >> None of them have anything to do with substitution.
>> >
>> >
>> > Perl disagrees.
>>
>> No it does not.
>>
>> I said "relates to how we match",
>
>
> You said "Huh?!" when I said g, c and p are match and substitution operator
> flag, not regex flags.
Ah, I see, this is a misunderstanding. "match and substitution
operator flags", to me reads quite differently to your original words
"match substitute operator flags". Additional I find the term "regex
flags" to be ambiguous.
> Perl gives errors when you use "g" and "c" as regex flags.
Here you seem to use "regex flags" where I would say "pattern
compilation (constructor) flags". And yes of course Perl complains
when you use a modifier which controls how the match is performed on a
pattern constructor which does not actually do any matching.
> $ perl -e'qr/foo/c'
>
> Having no space between pattern and following word is deprecated at -e line
> 1.
> Bareword found where operator expected at -e line 1, near "qr/foo/c"
> syntax error at -e line 1, near "qr/foo/c
> "
> Execution of -e aborted due to compilation errors.
>
> $ perl -e'qr/foo/g'
>
> Having no space between pattern and following word is deprecated at -e line
> 1.
> Bareword found where operator expected at -e line 1, near "qr/foo/g"
> syntax error at -e line 1, near "qr/foo/g
> "
> Execution of -e aborted due to compilation errors.
Do you find it productive when someone says something that you did not
understand and when you seek to clarify the issue they simply repeat
their words? In my experience most people find it really quite
annoying and rude. I certainly do.
> $ perl
> -we'qr/(?g:foo)/'
> Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g <--
> HERE :foo)/ at -e line 1.
This one is pretty obvious. It does not make any sense for _part_ of a
regex to match globally.
> $ perl
> -we'qr/(?c:foo)/'
> Useless (?c) - use /gc modifier in regex; marked by <-- HERE in m/(?c <--
> HERE :foo)/ at -e line 1.
ditto.
> $ perl -we'use re "/g";'
>
> Unknown regular expression flag "g" at -e line 1
I guess somebody MIGHT want every match to be global, but it seems
like any flag not legal on a qr// is forbidden in a use re. Which
would make sense given how it is structured in the code.
> $ perl -we'use re
> "/c";'
> Unknown regular expression flag "c" at -e line 1
Ditto.
> [It doesn't give errors for /p, though. but I don't see how that makes any
> sense.)]
Tom explained this already. /p can be embedded in any pattern and it
cannot be overridden, and indeed it is special in more ways than that
as it does not change match semantics, nor does it really change the
match process, all it does is tell the regex engine to do the copying
required to make $` and $& and $' work.
Having said that, in hindsight it probably was a mistake to allow /p on a qr//.
>> which means "the m// modifier". Not
>> the qr// modifier. A qr// operator does not *match* anything. It
>> *compiles* a pattern
>
>
> Exactly. Since qr// doesn't actually match, only regex pattern flags can be
> attached to it, which proves that "g" and "c" aren't regex flags. Contrary
> to perlre.
I find the term "regex flags" to be ambiguous and "Regex pattern
flags" to only be marginally better. Some of the terms I have used
elsewhere in this thread are equally bad. Since this ambiguity seems
to lead to confusion, lets try to come up with better terms. :-)
---------------------------------------------
1. Pattern semantics flags: /m /i /s /u /d /l /a
These modifiers change the meaning of specific meta-character, or
literal text. These apply to qr//, m// and s///
2. Pattern compilation flags: /x /o
These patterns change the process by which a pattern is compiled. /x
does so by causing the regex compiler to ignore specific parts of the
pattern passed in, and /o by determining how often it gets compiled.
These apply to qr//, m// and s///
3. Match control flags: /g /c
These control how the matching is to proceed, and only apply to m// and s///.
4. Substitutions flags: /e /r
These control the behavior of the substitution operator, and apply only to s///
---------------------------------------------
Unfortunately this leaves /p out, as it does not fit well into any of
the groups above, which I suspect is due to it really being a
workaround for the copying necessary to implement $&. I believe /p
should eventually go away (and I added it!) and be replaced by proper
copy on write semantics for match variables and the target string of a
regex. Anyway, i would probably put it in with the "Match control
modfiers", except for the fact it is legal in a qr//.
Yves
--
perl -Mre=debug -e "/just|another|perl|hacker/"
Thread Previous
|
Thread Next