Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'/e' regexp modifier is not recognized by re pragma #11935

Open
p5pRT opened this issue Feb 4, 2012 · 37 comments
Open

'/e' regexp modifier is not recognized by re pragma #11935

p5pRT opened this issue Feb 4, 2012 · 37 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 4, 2012

Migrated from rt.perl.org#109798 (status was 'open')

Searchable as RT109798$

@p5pRT
Copy link
Author

p5pRT commented Feb 4, 2012

From glitchmr@myopera.com

Created by glitchmr@myopera.com

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

Perl Info

Flags:
    category=library
    severity=low
    module=re

Site configuration information for perl 5.14.2:

Configured by sshd_server at Fri Oct  7 15:14:49 2011.

Summary of my perl5 (revision 5 version 14 subversion 2) configuration:
   
  Platform:
    osname=MSWin32, osvers=5.2, archname=MSWin32-x64-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='C:/mingw/bin/gcc.exe', ccflags ='-DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DWIN64 -DCONSERVATIVE -DPERL_TEXTMODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DHASATTRIBUTE -fno-strict-aliasing -mms-bitfields',
    optimize='-O2',
    cppflags='-DWIN32'
    ccversion='', gccversion='4.6.1', gccosandvers=''
    intsize=4, longsize=4, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='__int64', ivsize=8, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='C:\mingw\bin\g++.exe', ldflags ='-L"C:\Perl64\lib\CORE"'
    libpth=\lib
    libs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 -lbufferoverflowU -lmsvcrt
    perllibs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 -lbufferoverflowU -lmsvcrt
    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl514.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-mdll -L"C:\Perl64\lib\CORE"'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY


@INC for perl 5.14.2:
    C:/Perl64/site/lib
    C:/Perl64/lib
    .


Environment for perl 5.14.2:
    HOME=C:\Users\Konrad
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\Program Files (x86)\ActiveState Komodo IDE 7\;C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\PHP\;C:\Program Files (x86)\ATI Stream\bin\x86_64;C:\Program Files (x86)\ATI Stream\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\Parrot-3.8.0\bin;c:\rakudo\bin;C:\Program Files (x86)\Zend\MySQL51\bin;C:\Users\Konrad\AppData\Roaming\npm;C:\Program Files (x86)\nodejs\;C:\Program Files (x86)\Git\cmd;C:\Program Files (x86)\Git\bin;C:\Ruby193\bin;C:\Tcl\bin;C:\Program Files (x86)\ActiveState Komodo IDE 7\;C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\PHP\;C:\Program Files (x86)\ATI Stream\bin\x86_64;C:\Program Files (x86)\ATI Stream\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\Parrot-3.8.0\bin;c:\rakudo\bin;C:\Program Files (x86)\Zend\MySQL51\bin;C:\Users\Konrad\AppData\Roaming\npm;C:\Program Files (x86)\nodejs\;C:\Program Files (x86)\Git\cmd;C:\Program Files (x86)\Git\bin;C:\xampp\htdocs\lib\Cake\Console;C:\mingw\bin;C:\KDE\bin;C:\Python32;C:\android-sdk-windows\platform-tools;C:\android-sdk-windows\tools
    PERL_BADLANG (unset)
    PERL_JSON_BACKEND=JSON::XS
    PERL_YAML_BACKEND=YAML
    SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Feb 4, 2012

From @jkeenan

On Sat Feb 04 04​:05​:02 2012, glitchmr@​myopera.com wrote​:

This is a bug report for perl from glitchmr@​myopera.com,
generated with the help of perlbug 1.39 running under perl 5.14.2.

-----------------------------------------------------------------
[Please describe your issue here]

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.

Agreed. I couldn't find any discussion of '/e' in 'perldoc re'

C​:\\Users\\Konrad>perl \-e "use re '/e'"
Unknown regular expression flag "e" at \-e line 1

@p5pRT
Copy link
Author

p5pRT commented Feb 4, 2012

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @ikegami

On Sat Feb 04 04​:05​:02 2012, glitchmr@​myopera.com wrote​:

This is a bug report for perl from glitchmr@​myopera.com,
generated with the help of perlbug 1.39 running under perl 5.14.2.

-----------------------------------------------------------------
[Please describe your issue here]

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.

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @ikegami

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&#8203;:\\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.

(I find this very odd that p, g and c are regex flags instead of match
substitute operator flags, but they are are.)

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From tchrist@perl.com

"Eric Brine via RT" <perlbug-followup@​perl.org> wrote
  on Sat, 04 Feb 2012 16​:19​:41 PST​:

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.

That's incorrect, and potentially misleading.

With blank lines removed for brevity, these are
the only pattern modifiers​:

  =head2 Pattern Modifiers
  =begin table picture Regular expression modifiers
  =headrow
  =row
  =cell Modifier
  =cell Meaning
  =bodyrows
  =row
  =cell C</i>
  =cell Ignore alphabetic case distinctions (case insensitive).
  =row
  =cell C</s>
  =cell Let C<.> also match newline.
  =row
  =cell C</m>
  =cell Let C<^> and C<$> also match next to embedded C<\n>.
  =row
  =cell C</x>
  =cell Ignore (most) whitespace and permit comments in pattern.
  =row
  =cell
  =row
  =cell C</o>
  =cell Compile pattern once only.
  =row
  =cell C</p>
  =cell Preserve C<${^PREMATCH}>, C<${^MATCH}>, and C<${^POSTMATCH}> variables.
  =row
  =cell
  =row
  =cell C</d>
  =cell Dual ASCII–Unicode mode charset behavior (old default)
  =row
  =cell C</a>
  =cell ASCII charset behavior
  =row
  =cell C</u>
  =cell Unicode charset behavior (new default)
  =row
  =cell C</l>
  =cell the run-time locale’s charset behavior (default under R<use locale>)
  =end table

That's all. Those apply to patterns.

These flags, however, apply to the match operator, which is different​:

  =head2 The m// Operator (Matching)
  =begin table picture m// Modifiers
  =headrow
  =row
  =cell Modifier
  =cell Meaning
  =bodyrows
  =row
  =cell C</i>
  =cell Ignore alphabetic case.
  =row
  =cell C</m>
  =cell Let C<^> and C<$> also match next to embedded C<\n>.
  =row
  =cell C</s>
  =cell Let C<.> also match newline.
  =row
  =cell C</x>
  =cell Ignore (most) whitespace and permit comments in pattern.
  =row
  =cell C</o>
  =cell Compile pattern once only.
  =row
  =cell C</p>
  =cell Preserve the matched string.
  =row
  =cell
  =row
  =cell C</d>
  =cell Dual ASCII–Unicode mode charset behavior (old default).
  =row
  =cell C</u>
  =cell Unicode charset behavior (new default).
  =row
  =cell C</a>
  =cell ASCII charset behavior
  =row
  =cell C</l>
  =cell The run-time locale’s charset behavior (default under R<use locale>).
  =row
  =cell
  =row
  =cell C</g>
  =cell Globally find all matches.
  =row
  =cell C</cg>
  =cell Allow continued search after failed C</g> match.
  =end table

Here are the s/// flags​:

  =head2 The s/// Operator (Substitution)
  =begin table picture s/// Modifiers
  =headrow
  =row
  =cell Modifier
  =cell Meaning
  =bodyrows
  =row
  =cell C</i>
  =cell Ignore alphabetic case (when matching).
  =row
  =cell C</m>
  =cell Let C<^> and C<$> also match next to embedded C<\n>.
  =row
  =cell C</s>
  =cell Let C<.> also match newline.
  =row
  =cell C</x>
  =cell Ignore (most) whitespace and permit comments in pattern.
  =row
  =cell C</o>
  =cell Compile pattern once only.
  =row
  =cell C</p>
  =cell Preserve the matched string.
  =row
  =cell
  =row
  =cell C</d>
  =cell Dual ASCII–Unicode mode charset behavior (old default).
  =row
  =cell C</u>
  =cell Unicode charset behavior (new default).
  =row
  =cell C</a>
  =cell ASCII charset behavior.
  =row
  =cell C</l>
  =cell The run-time locale’s charset behavior (default under R<use locale>).
  =row
  =cell
  =row
  =cell C</g>
  =cell Replace globally, that is, all occurrences.
  =row
  =cell C</r>
  =cell Return substitution and leave the original string untouched.
  =row
  =cell C</e>
  =cell Evaluate the right side as an expression.
  =end table

And tr/// has its own as well​:

  =begin table picture tr/// Modifiers
  =headrow
  =row
  =cell Modifier
  =cell Meaning
  =bodyrows
  =row
  =cell C</c>
  =cell Complement R<SEARCHLIST>.X</c pattern modifier​:c5 pattern>
  =row
  =cell C</d>
  =cell Delete found but unreplaced characters.X</d pattern modifier​:d pattern>
  =row
  =cell C</s>
  =cell Squash duplicate replaced characters.X</s pattern modifier​:s pattern>
  =row
  =cell C</r>
  =cell Return transliteration and leave the original string untouched.
  =end table

See? Four distinct sets of flags.

(I find this very odd that p, g and c are regex flags instead
of match substitute operator flags, but they are are.)

You should find it odd, because they aren't.

  $ perl -E 'use re "/e"; say "ok"'
  Unknown regular expression flag "e" at -e line 1
  ok

  $ perl -E 'use re "/g"; say "ok"'
  Unknown regular expression flag "g" at -e line 1
  ok

  $ perl -E 'use re "/c"; say "ok"'
  Unknown regular expression flag "c" at -e line 1
  ok

  $ perl -E 'use re "/p"; say "ok"'
  ok

What's going on with the first three is that it isn't properly dying.

  $ perl -Mwarnings=FATAL,all -E 'use re "/g"; say "ok"'
  Unknown regular expression flag "g" at -e line 1
  ok

That's a bug.

What's going on with the last one is more subtle. /p can be
embedded in a pattern with (?p), but it cannot be turned off
once turned on.

Anyway, probably perlre should be clearer (read​: more correct)
about the s/uper/man/mxyzptlk flags, and that jazz.

--tom

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @ikegami

On Sat, Feb 4, 2012 at 8​:24 PM, Tom Christiansen <tchrist@​perl.com> wrote​:

"Eric Brine via RT" <perlbug-followup@​perl.org> wrote
on Sat, 04 Feb 2012 16​:19​:41 PST​:

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.

That's incorrect, and potentially misleading.

With blank lines removed for brevity, these are
the only pattern modifiers​:

You removed "g" and "c", but they are accepted in patterns.

perl -wcE"qr/(?c​:foo)/;"
Useless (?c) - use /gc modifier in regex; marked by <-- HERE in m/(?c <--
HERE :foo)/ at -e line 1.
-e syntax OK

perl -wcE"qr/(?g​:foo)/;"
Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g <--
HERE :foo)/ at -e line 1.
-e syntax OK

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @ikegami

On Sat, Feb 4, 2012 at 8​:24 PM, Tom Christiansen <tchrist@​perl.com> wrote​:

"Eric Brine via RT" <perlbug-followup@​perl.org> wrote
on Sat, 04 Feb 2012 16​:19​:41 PST​:

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.

That's incorrect, and potentially misleading.

With blank lines removed for brevity, these are

the only pattern modifiers​:

You removed "g" and "c", but they are accepted in patterns​:

perl -wcE"qr/(?c​:foo)/;"
Useless (?c) - use /gc modifier in regex; marked by <-- HERE in m/(?c <--
HERE :foo)/ at -e line 1.
-e syntax OK

perl -wcE"qr/(?g​:foo)/;"
Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g <--
HERE :foo)/ at -e line 1.
-e syntax OK

I don't know why that is.

If anything is misleading is that they are listed as pattern modifiers
(which are listed in perlre) instead of operator modifiers (which are
listed in perlop).

- Eric

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From tchrist@perl.com

Eric Brine <ikegami@​adaelis.com> wrote
  on Sat, 04 Feb 2012 23​:54​:37 EST​:

You removed "g" and "c", but they are accepted in patterns​:

perl -wcE"qr/(?c​:foo)/;"
Useless (?c) - use /gc modifier in regex; marked by <-- HERE in m/(?c <--
HERE :foo)/ at -e line 1.
-e syntax OK

perl -wcE"qr/(?g​:foo)/;"
Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g <--
HERE :foo)/ at -e line 1.
-e syntax OK

I don't know why that is.

I removed them because they are non-sensical, and I consider it a bug
that they are accepted but whined about as pattern operators.

If anything is misleading is that they are listed as pattern modifiers
(which are listed in perlre) instead of operator modifiers (which are
listed in perlop).

Something else that's misleading is having to look in two different
places for those things.

--tom

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @demerphq

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 $`, $&amp;, $', 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.

On the other hand /e does, as does /ee

Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @demerphq

On 5 February 2012 05​:48, Eric Brine <ikegami@​adaelis.com> wrote​:

On Sat, Feb 4, 2012 at 8​:24 PM, Tom Christiansen <tchrist@​perl.com> wrote​:

"Eric Brine via RT" <perlbug-followup@​perl.org> wrote
  on Sat, 04 Feb 2012 16​:19​:41 PST​:

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.

That's incorrect, and potentially misleading.

With blank lines removed for brevity, these are
the only pattern modifiers​:

You removed "g" and "c", but they are accepted in patterns.

perl -wcE"qr/(?c​:foo)/;"
Useless (?c) - use /gc modifier in regex; marked by <-- HERE in m/(?c <--
HERE :foo)/ at -e line 1.
-e syntax OK

perl -wcE"qr/(?g​:foo)/;"
Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g <--
HERE :foo)/ at -e line 1.
-e syntax OK

Personally I consider "ignored and produce warnings" to be quite
different from "accepted in patterns".

Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @demerphq

On 5 February 2012 11​:56, Tom Christiansen <tchrist@​perl.com> wrote​:

Eric Brine <ikegami@​adaelis.com> wrote
  on Sat, 04 Feb 2012 23​:54​:37 EST​:

You removed "g" and "c", but they are accepted in patterns​:

perl -wcE"qr/(?c​:foo)/;"
Useless (?c) - use /gc modifier in regex; marked by <-- HERE in m/(?c <--
HERE :foo)/ at -e line 1.
-e syntax OK

perl -wcE"qr/(?g​:foo)/;"
Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g <--
HERE :foo)/ at -e line 1.
-e syntax OK

I don't know why that is.

I removed them because they are non-sensical, and I consider it a bug
that they are accepted but whined about as pattern operators.

Why? You think throwing a fatal is preferred? They do nothing, they
have no affect.

If anything is misleading is that they are listed as pattern modifiers
(which are listed in perlre) instead of operator modifiers (which are
listed in perlop).

Something else that's misleading is having to look in two different
places for those things.

Yes agreed.

Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From tchrist@perl.com

Why? You think throwing a fatal is preferred? They do nothing, they
have no affect.

How can this not be a bug?

  $ perl -E 'no warnings; use re "/g"; say "gosh that was ok, then, eh?"'
  Unknown regular expression flag "g" at -e line 1
  gosh that was ok, then, eh?

  $ perl -E 'use warnings FATAL => "all"; use re "/g"; say "gosh that was ok, then, eh?"'
  Unknown regular expression flag "g" at -e line 1
  gosh that was ok, then, eh?

  $ perl -E 'use warnings FATAL => "all"; use re "/WTF"; say "gosh that was ok, then, eh?"'
  Unknown regular expression flag "W" at -e line 1
  gosh that was ok, then, eh?

I can't disable them.
I can't trap them.
They're stupid noise.

Yes, I want a fatal.

I certainly want to be *able* to have a fatal.

I think they should be a fatal.

They most definitely shouldn't be noise.

--tom

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @demerphq

On 5 February 2012 02​:24, Tom Christiansen <tchrist@​perl.com> wrote​:

"Eric Brine via RT" <perlbug-followup@​perl.org> wrote
  on Sat, 04 Feb 2012 16​:19​:41 PST​:

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.

That's incorrect, and potentially misleading.

With blank lines removed for brevity, these are
the only pattern modifiers​:

Please Tom, it is very difficult to discuss things that are a mass of
pod extracts. Next time either render the POD and then paste it as
text, or don't use POD at all.

   =head2 Pattern Modifiers
   =begin table picture Regular expression modifiers

....

That's all.  Those apply to patterns.

These flags, however, apply to the match operator, which is different​:

   =head2 The m// Operator (Matching)

....

Here are the s/// flags​:

   =head2 The s/// Operator (Substitution)
...

And tr/// has its own as well​:
   =begin table picture tr/// Modifiers

tr/// has nothing to do with the regex engine, IMO it has no place in
a discussion about regular expressions.

See?  Four distinct sets of flags.

I personally would analyse modifiers in a very different way.

As far as I am concerned there are only three types of regex modifier.

1. Modifiers which change the semantics of how a pattern is interpreted

/m /s /i /u /d /l /a

2. Modifiers which change the behavior of the matching process or how
a pattern is compiled

/x /o /g /c /p

3. Modifiers which change the behavior of the substitution process.

/e /ee /r

(I find this very odd that p, g and c are regex flags instead
of match substitute operator flags, but they are are.)

You should find it odd, because they aren't.

I don't really understand this analysis. This is a new feature, what
it does or not do is hardly definitive in any way.

   $ perl -E 'use re "/e"; say "ok"'
   Unknown regular expression flag "e" at -e line 1
   ok

   $ perl -E 'use re "/g"; say "ok"'
   Unknown regular expression flag "g" at -e line 1
   ok

   $ perl -E 'use re "/c"; say "ok"'
   Unknown regular expression flag "c" at -e line 1
   ok

   $ perl -E 'use re "/p"; say "ok"'
   ok

This one is pretty weird. It makes some sense, but I cant help but
wonder why someone would use this instead of using $` and $&amp; and $'
directly.

What's going on with the first three is that it isn't properly dying.

   $ perl -Mwarnings=FATAL,all -E 'use re "/g"; say "ok"'
   Unknown regular expression flag "g" at -e line 1
   ok

That's a bug.

Is it, it seems like it warns, which would be a deliberate action, so
I can only assume it is a feature.

What's going on with the last one is more subtle.  /p can be
embedded in a pattern with (?p), but it cannot be turned off
once turned on.

Correct.

Anyway, probably perlre should be clearer (read​: more correct)
about the s/uper/man/mxyzptlk flags, and that jazz.

Erm, maybe, but personally I would not document it the way you did. It
makes sense as documentation for the individual operators, but IMO the
division I used is much closer to the internals.

cheers
Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @demerphq

On 5 February 2012 18​:44, Tom Christiansen <tchrist@​perl.com> wrote​:

Why? You think throwing a fatal is preferred? They do nothing, they
have no affect.

How can this not be a bug?

My personal feeling on this is that it matches the general tradition
of perl not croaking when no harm is done by not croaking. Since the
operators are meaningless why break the code over a typo?

I did not implement the feature, but considering the warning was
deliberately added I assume it is a feature.

   $ perl -E 'no warnings; use re "/g"; say "gosh that was ok, then, eh?"'
   Unknown regular expression flag "g" at -e line 1
   gosh that was ok, then, eh?

   $ perl -E 'use warnings FATAL => "all"; use re "/g"; say "gosh that was ok, then, eh?"'
   Unknown regular expression flag "g" at -e line 1
   gosh that was ok, then, eh?

   $ perl -E 'use warnings FATAL => "all"; use re "/WTF"; say "gosh that was ok, then, eh?"'
   Unknown regular expression flag "W" at -e line 1
   gosh that was ok, then, eh?

I can't disable them.
I can't trap them.
They're stupid noise.

So then fix your code.

Yes, I want a fatal.

Well, I personally could see it either way, and am inclined slightly
towards the no-die policy.

I certainly want to be *able* to have a fatal.

I think they should be a fatal.

They most definitely shouldn't be noise.

Warnings are noise?

Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From tchrist@perl.com

Warnings are noise?

Warnings that are not subject to the warnings pragma are not
warnings; they're noise.

I cannot enable them.
I cannot disable them.
I cannot trap them.
I cannot fatalize them.

Yes, they're noise.

--tom

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @demerphq

On 5 February 2012 19​:01, Tom Christiansen <tchrist@​perl.com> wrote​:

Warnings are noise?

Warnings that are not subject to the warnings pragma are not
warnings; they're noise.

Oh, I see.

I cannot enable them.
I cannot disable them.
I cannot trap them.
I cannot fatalize them.

Yes, they're noise.

Well the fact that you cant do this ddes seem like a bug, I
misunderstood your point.

Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From tchrist@perl.com

demerphq <demerphq@​gmail.com> wrote
  on Sun, 05 Feb 2012 18​:55​:22 +0100​:

Please Tom, it is very difficult to discuss things that are a mass of
pod extracts. Next time either render the POD and then paste it as
text, or don't use POD at all.

Guilty. Sorry. Yes, you're right. Am rushed.

tr/// has nothing to do with the regex engine, IMO it has no place in
a discussion about regular expressions.

I don't want people slingshotting around looking for where the devil the
/mxyzptlk modifiers get explain.

The four (or five) pick-your-own-quotes pseudofunctions qr//, m//, s///,
and tr/// (and y///) are distinct from the others in taking modifiers in
the /mxyzptlk slot, whereas q//, qq//, qx//, and qw// do not.

Also, all four (or five) of the flaggy PYOQ pseudofuncs can be found
using the =~ operator. Yes, even qr//, for all the good it'll do you.

  $ perl -E 'say "frobnitz" =~ qr/([AEIOUWY])/i'
  o

And s///'s /r modifier does exactly the same thing as tr///'s /r
modifier does.

  % perl -E 'say "frobnitz" =~ y/aeiouy/yuoiea/r'
  fribnotz

But I do understand that tr/// doesn't belong in a section on pattern
matching. Had to put it somewhere, though, and I just refused to move it
to a functions area or an operators area. Larry stuck this in there,
fess'ing up to the matter​:

  The tr/// transliteration operator does not interpolate variables; it
  doesn’t even use regular expressions! (In fact, it probably doesn’t
  belong in this chapter at all, but we couldn’t think of a better place
  to put it.)

3. Modifiers which change the behavior of the substitution process.

/e /ee /r

Wait, you mean the RHS not the LHS, right? That's why you
didn't mention /g and /gc, because they apply to s///'s LHS?

But why mention /ee distinct from /e? It's not special.
You can have /eee and /eeee if you want. eeeeetc.

Erm, maybe, but personally I would not document it the way you did. It
makes sense as documentation for the individual operators, but IMO the
division I used is much closer to the internals.

I figure people looking for what modifiers they can apply to
the flaggy PYOQ pseudofuncs should be able to find all those
collected into one place.

The /dual things are so strange. They're a mutually-dependent
radio group where turning one on turns the others off. Highlander
options.

We could use a better way to do things. I'd like to figure out a way to make
those real words in there, just just letters. (?x-i​:foo) is fine and all, but
we're starting to burst at the seams -- hence my /mxyzptlk remarks.

I find qr/PATTERN/msixpodual to be way out there, and adding in
m/PATTERN/msixpodualgc and it's just too much. Then we get to
(?adlupimsx-imsx) plus the alternate (?^alupimsx), and that's just
beyond the pale.

Plus now those aren't even listed in the same order as the m//flags are,
so you can't have a dependable mnemonic.

Might as well use /mxyzptlk after all, eh?

--tom

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @khwilliamson

On 02/05/2012 11​:27 AM, Tom Christiansen wrote​:

demerphq<demerphq@​gmail.com> wrote
on Sun, 05 Feb 2012 18​:55​:22 +0100​:

Please Tom, it is very difficult to discuss things that are a mass of
pod extracts. Next time either render the POD and then paste it as
text, or don't use POD at all.

Guilty. Sorry. Yes, you're right. Am rushed.

tr/// has nothing to do with the regex engine, IMO it has no place in
a discussion about regular expressions.

I don't want people slingshotting around looking for where the devil the
/mxyzptlk modifiers get explain.

The four (or five) pick-your-own-quotes pseudofunctions qr//, m//, s///,
and tr/// (and y///) are distinct from the others in taking modifiers in
the /mxyzptlk slot, whereas q//, qq//, qx//, and qw// do not.

Also, all four (or five) of the flaggy PYOQ pseudofuncs can be found
using the =~ operator. Yes, even qr//, for all the good it'll do you.

 $ perl \-E 'say "frobnitz" =~ qr/\(\[AEIOUWY\]\)/i'
 o

And s///'s /r modifier does exactly the same thing as tr///'s /r
modifier does.

 % perl \-E 'say "frobnitz" =~ y/aeiouy/yuoiea/r'
 fribnotz

But I do understand that tr/// doesn't belong in a section on pattern
matching. Had to put it somewhere, though, and I just refused to move it
to a functions area or an operators area. Larry stuck this in there,
fess'ing up to the matter​:

 The tr/// transliteration operator does not interpolate variables; it
 doesn’t even use regular expressions\!  \(In fact\, it probably doesn’t
 belong in this chapter at all\, but we couldn’t think of a better place
 to put it\.\)

3. Modifiers which change the behavior of the substitution process.

/e /ee /r

Wait, you mean the RHS not the LHS, right? That's why you
didn't mention /g and /gc, because they apply to s///'s LHS?

But why mention /ee distinct from /e? It's not special.
You can have /eee and /eeee if you want. eeeeetc.

Erm, maybe, but personally I would not document it the way you did. It
makes sense as documentation for the individual operators, but IMO the
division I used is much closer to the internals.

I figure people looking for what modifiers they can apply to
the flaggy PYOQ pseudofuncs should be able to find all those
collected into one place.

The /dual things are so strange. They're a mutually-dependent
radio group where turning one on turns the others off. Highlander
options.

We could use a better way to do things. I'd like to figure out a way to make
those real words in there, just just letters. (?x-i​:foo) is fine and all, but
we're starting to burst at the seams -- hence my /mxyzptlk remarks.

I find qr/PATTERN/msixpodual to be way out there, and adding in
m/PATTERN/msixpodualgc and it's just too much. Then we get to
(?adlupimsx-imsx) plus the alternate (?^alupimsx), and that's just
beyond the pale.

Plus now those aren't even listed in the same order as the m//flags are,
so you can't have a dependable mnemonic.

Might as well use /mxyzptlk after all, eh?

--tom

Patches welcome!

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @demerphq

On 5 February 2012 19​:27, Tom Christiansen <tchrist@​perl.com> wrote​:

demerphq <demerphq@​gmail.com> wrote
  on Sun, 05 Feb 2012 18​:55​:22 +0100​:

Please Tom, it is very difficult to discuss things that are a mass of
pod extracts. Next time either render the POD and then paste it as
text, or don't use POD at all.

Guilty.  Sorry.  Yes, you're right.  Am rushed.

These things happen. But please *do* try.

tr/// has nothing to do with the regex engine, IMO it has no place in
a discussion about regular expressions.

I don't want people slingshotting around looking for where the devil the
/mxyzptlk modifiers get explain.

The four (or five) pick-your-own-quotes pseudofunctions qr//, m//, s///,
and tr/// (and y///) are distinct from the others in taking modifiers in
the /mxyzptlk slot, whereas q//, qq//, qx//, and qw// do not.

Also, all four (or five) of the flaggy PYOQ pseudofuncs can be found
using the =~ operator.  Yes, even qr//, for all the good it'll do you.

   $ perl -E 'say "frobnitz" =~ qr/([AEIOUWY])/i'
   o

And s///'s /r modifier does exactly the same thing as tr///'s /r
modifier does.

   % perl -E 'say "frobnitz" =~ y/aeiouy/yuoiea/r'
   fribnotz

But I do understand that tr/// doesn't belong in a section on pattern
matching.   Had to put it somewhere, though, and I just refused to move it
to a functions area or an operators area.  Larry stuck this in there,
fess'ing up to the matter​:

   The tr/// transliteration operator does not interpolate variables; it
   doesn’t even use regular expressions!  (In fact, it probably doesn’t
   belong in this chapter at all, but we couldn’t think of a better place
   to put it.)

Well fair enough. You are talking about a book tho, and I was more
talking about the documentation for perl.

3. Modifiers which change the behavior of the substitution process.

/e /ee /r

Wait, you mean the RHS not the LHS, right?  That's why you
didn't mention /g and /gc, because they apply to s///'s LHS?

They dont change how _substitution_ is performed. They change how the
_match_process_ works. I do not see any benefit by conflating the two.

You see, the way you are analysing overlooks the following (to me)
important observation​:

Any modifier that affects a qr// is legal in an m//
Any modifier legal in an m// is legal in a s///.

Or in other words​: qr// compiles a pattern, m// compiles a pattern and
execute it, and s/// compiles a pattern and then uses it for
substitution. Any modifier for compiling a pattern is legal in all
three. Any modifier for executing a pattern is legal in m// and s///,
and s/// has a few modifiers which are specific to substitution.

Your analysis seesm to ignore this heirarchy in a way that I do not
consider useful. One must essentially memorize the same list three
times, instead of understand which behaviour the modifier changes.

But why mention /ee distinct from /e?  It's not special.
You can have /eee and /eeee if you want.  eeeeetc.

Yes I know, but /ee and /eeee are synonyms. And /ee *is* distinct from
/e. See the docs for more details.

Erm, maybe, but personally I would not document it the way you did. It
makes sense as documentation for the individual operators, but IMO the
division I used is much closer to the internals.

I figure people looking for what modifiers they can apply to
the flaggy PYOQ pseudofuncs should be able to find all those
collected into one place.

But they are collected in a way that is not useful.

The /dual things are so strange.  They're a mutually-dependent
radio group where turning one on turns the others off.  Highlander
options.

Not much choixe there.

We could use a better way to do things. I'd like to figure out a way to make
those real words in there, just just letters. (?x-i​:foo) is fine and all, but
we're starting to burst at the seams -- hence my /mxyzptlk remarks.

I find qr/PATTERN/msixpodual to be way out there, and adding in
m/PATTERN/msixpodualgc and it's just too much.  Then we get to
(?adlupimsx-imsx) plus the alternate (?^alupimsx), and that's just
beyond the pale.

Plus now those aren't even listed in the same order as the m//flags are,
so you can't have a dependable mnemonic.

Might as well use /mxyzptlk after all, eh?

I dont understand your point here really. We have certain modifiers
which change certain behavior. I dont see how mnemonics are relevent.

cheers,
Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @tamias

On Sun, Feb 05, 2012 at 07​:46​:55PM +0100, demerphq wrote​:

On 5 February 2012 19​:27, Tom Christiansen <tchrist@​perl.com> wrote​:

But why mention /ee distinct from /e?  It's not special.
You can have /eee and /eeee if you want.  eeeeetc.

Yes I know, but /ee and /eeee are synonyms. And /ee *is* distinct from
/e. See the docs for more details.

/ee and /eeee are not synonyms. /ee performs two evals; /eeee performs
four.

Ronald

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2012

From @ikegami

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&#8203;:\\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 $`, $&amp;, $', 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.

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.

@p5pRT
Copy link
Author

p5pRT commented Feb 6, 2012

From @demerphq

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 $`, $&amp;, $', 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", which means "the m// modifier". Not
the qr// modifier. A qr// operator does not *match* anything. It
*compiles* a pattern, but does not use it to match. You have to use
m//, or a qr object on the rhs of a =~ to do a match.

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.

$ perl -e'm/foo/g'
$ perl -e'm/foo/c'
$ perl -e'm/foo/p'

cheers,
Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Feb 6, 2012

From @demerphq

On 5 February 2012 22​:33, Ronald J Kimball <rjk@​tamias.net> wrote​:

On Sun, Feb 05, 2012 at 07​:46​:55PM +0100, demerphq wrote​:

On 5 February 2012 19​:27, Tom Christiansen <tchrist@​perl.com> wrote​:

But why mention /ee distinct from /e?  It's not special.
You can have /eee and /eeee if you want.  eeeeetc.

Yes I know, but /ee and /eeee are synonyms. And /ee *is* distinct from
/e. See the docs for more details.

/ee and /eeee are not synonyms.  /ee performs two evals; /eeee performs
four.

I stand corrected, thanks for pointing that out, I definitely did not know that.

$ perl -wle'sub foobar{"zoo"}; sub zoo { "giraffe" }; $_=qq("foo");
$x=qq(. "bar"); s/("foo")/$1 . $x/; print'
"foo" . . "bar"
$ perl -wle'sub foobar{"zoo"}; sub zoo { "giraffe" }; $_=qq("foo");
$x=qq(. "bar"); s/("foo")/$1 . $x/e; print'
"foo". "bar"
$ perl -wle'sub foobar{"zoo"}; sub zoo { "giraffe" }; $_=qq("foo");
$x=qq(. "bar"); s/("foo")/$1 . $x/ee; print'
foobar
$ perl -wle'sub foobar{"zoo"}; sub zoo { "giraffe" }; $_=qq("foo");
$x=qq(. "bar"); s/("foo")/$1 . $x/eee; print'
zoo
$ perl -wle'sub foobar{"zoo"}; sub zoo { "giraffe" }; $_=qq("foo");
$x=qq(. "bar"); s/("foo")/$1 . $x/eeee; print'
giraffe

I do wonder if this is intentional or an interesting implementation side effect.

Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Feb 6, 2012

From tchrist@perl.com

I do wonder if this is intentional or an interesting implementation side effect.

It's been that way since time immemorial, but I can no longer
recall whether it was initially done by intent.

--tom

@p5pRT
Copy link
Author

p5pRT commented Feb 6, 2012

From @pjcj

On Mon, Feb 06, 2012 at 04​:18​:38AM -0700, Tom Christiansen wrote​:

I do wonder if this is intentional or an interesting implementation side effect.

It's been that way since time immemorial, but I can no longer
recall whether it was initially done by intent.

And it's seen far less frequently nowadays. Back then we had a general
tendency to be a little more cavalier in such matters.

--
Paul Johnson - paul@​pjcj.net
http​://www.pjcj.net

@p5pRT
Copy link
Author

p5pRT commented Feb 6, 2012

From tchrist@perl.com

Paul Johnson <paul@​pjcj.net> wrote
  on Mon, 06 Feb 2012 12​:42​:42 +0100​:

On Mon, Feb 06, 2012 at 04​:18​:38AM -0700, Tom Christiansen wrote​:

I do wonder if this is intentional or an interesting implementation s<SNIP>

It's been that way since time immemorial, but I can no longer
recall whether it was initially done by intent.

And it's seen far less frequently nowadays. Back then we had a general
tendency to be a little more cavalier in such matters.

What, /ee? It's the normal way to get single variables interpolated.

A single /e is like an eval { }, and compiled at compile time.
A double /e is more like an eval "", and gets compiled at run time.

But I never much go beyond that, because that's writing
eval eval foo().

--tom

@p5pRT
Copy link
Author

p5pRT commented Feb 6, 2012

From @ikegami

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&#8203;:\\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 $`, $&amp;, $', 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.

Perl gives errors when you use "g" and "c" as regex flags.

$ 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.

$ perl
-we'qr/(?g​:foo)/'

Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g <--
HERE :foo)/ at -e line 1.

$ perl
-we'qr/(?c​:foo)/'

Useless (?c) - use /gc modifier in regex; marked by <-- HERE in m/(?c <--
HERE :foo)/ at -e line 1.

$ perl -we'use re "/g";'
Unknown regular expression flag "g" at -e line 1

$ perl -we'use re
"/c";'

Unknown regular expression flag "c" at -e line 1

[It doesn't give errors for /p, though. but I don't see how that makes any
sense.)]

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.

- Eric

@p5pRT
Copy link
Author

p5pRT commented Feb 7, 2012

From @demerphq

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 $`, $&amp;, $', 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 $&amp; 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/"

@p5pRT
Copy link
Author

p5pRT commented Feb 7, 2012

From @ikegami

On Mon, Feb 6, 2012 at 9​:23 PM, demerphq <demerphq@​gmail.com> wrote​:

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".

oops, typo!

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".

Noted.

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.

That's good. That's what I would expect. The problem is that perlre lumps
"g", "c" and "p" into the documentation for regex pattern compilation flags.

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. :-)

perlre simply calls them "modifiers" and "flags modifiers". The re pragma
calls them "flags" and "modifiers". It could definitely be improved.


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

Sounds good. A few comment/nits​:

I'm not sure a distinction is needed between (1) and (2), and it will lead
to having to the following mouthful​: "(?​:) accepts pattern semantic flags
and pattern compilation flags".

perlop lists /ee in addition to /e, so /ee should be listed explicitly here.

Because of where it can be used, I'd place /p under (2). (I believe it
should be in (3), but that's not how it was implemented.)

- Eric

@p5pRT
Copy link
Author

p5pRT commented Feb 7, 2012

From @b2gills

On Mon, Feb 6, 2012 at 11​:04 PM, Eric Brine <ikegami@​adaelis.com> wrote​:

On Mon, Feb 6, 2012 at 9​:23 PM, demerphq <demerphq@​gmail.com> wrote​:

...

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.

That's good. That's what I would expect. The problem is that perlre lumps
"g", "c" and "p" into the documentation for regex pattern compilation flags.

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. :-)

perlre simply calls them "modifiers" and "flags modifiers". The re pragma
calls them "flags" and "modifiers". It could definitely be improved.

---------------------------------------------
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

Sounds good. A few comment/nits​:

I'm not sure a distinction is needed between (1) and (2), and it will lead
to having to the following mouthful​: "(?​:) accepts pattern semantic flags
and pattern compilation flags".

While (1) and (2) could be grouped together by what they can apply to;
I think it would be quite hard to come up with a phrase to describe them
that doesn't also include any of the other flags.

The phrase​:
Pattern semantics flags
is very unambiguous as to what is included in that group.

If you wanted to describe both (1) and (2)​:
"(?​:) accepts pattern semantic, and compilation flags"

I would like to note that the important words from (1) and (2)
are "semantic" and "compilation"

Also there is actually a difference between (1) and (2),
the flags from (1) can be applied with "(?i​:)"
The flags from (2) can only be applied to the whole pattern/match/substitution.

( Perhaps we should refer to qr// as a pattern. Just a random thought. )

perlop lists /ee in addition to /e, so /ee should be listed explicitly here.

If we do refer to /ee, perhaps we should note that you can append as
many /e's as you want.

Because of where it can be used, I'd place /p under (2). (I believe it
should be in (3), but that's not how it was implemented.)

I agree with this.

@p5pRT
Copy link
Author

p5pRT commented Feb 12, 2012

From @cpansprout

On Mon Feb 06 03​:49​:30 2012, tom christiansen wrote​:

Paul Johnson <paul@​pjcj.net> wrote
on Mon, 06 Feb 2012 12​:42​:42 +0100​:

On Mon, Feb 06, 2012 at 04​:18​:38AM -0700, Tom Christiansen wrote​:

I do wonder if this is intentional or an interesting
implementation s<SNIP>

It's been that way since time immemorial, but I can no longer
recall whether it was initially done by intent.

And it's seen far less frequently nowadays. Back then we had a
general
tendency to be a little more cavalier in such matters.

What, /ee? It's the normal way to get single variables interpolated.

A single /e is like an eval { }, and compiled at compile time.

A single /e just makes the rhs an expression with no ‘eval’ and no block.

A double /e is more like an eval "", and gets compiled at run time.

But I never much go beyond that, because that's writing
eval eval foo().

And the number of evals is one less than the number of e’s.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Feb 12, 2012

From tchrist@perl.com

"Father Chrysostomos via RT" <perlbug-followup@​perl.org>
  wrote on Sun, 12 Feb 2012 00​:15​:42 PST​:

It's been that way since time immemorial, but I can no longer
recall whether it was initially done by intent.

And it's seen far less frequently nowadays. Back then we had a
general tendency to be a little more cavalier in such matters.

What, /ee? It's the normal way to get single variables interpolated.

A single /e is like an eval { }, and compiled at compile time.

A single /e just makes the rhs an expression with no ‘eval’ and no block.

I was using eval in the sense of "to evaluate an expression", not eval in
the sense of "to catch exceptions". I was trying to explain it with the
/e mnemonic always meaning eval, even though that risks confusion about
what happens whether exceptions are caught.

  0. s/PATTERN/QQ_STRING/;
  1. s/PATTERN/ EXPR/e; # no catch
  2. s/PATTERN/ EVAL EXPR/ee; # yes catch
  3. s/PATTERN/EVAL EVAL EXPR/eee; # yes catch
  (etc.)

In case 1, the replacement value is the result of evaluating EXPR.
EXPR was syntax-checked and compiled at compile time, and there is
no catching of exceptions.

I don't think it is forbidden to speak of evaluating expressions
at runtime. I'm not thrilled wtih trying to explain that it's
really do{EXPR} intead of eval{EXPR}. One evaluates expressions;
what better word would you suggest there?

A double /e is more like an eval "", and gets compiled at run time.

But I never much go beyond that, because that's writing
eval eval foo().

And the number of evals is one less than the number of e’s.

The number of evaluations is equal to the number of e’s.

--tom

@p5pRT
Copy link
Author

p5pRT commented Feb 12, 2012

From @cpansprout

On Sun Feb 12 07​:18​:57 2012, tom christiansen wrote​:

"Father Chrysostomos via RT" <perlbug-followup@​perl.org>
wrote on Sun, 12 Feb 2012 00​:15​:42 PST​:

It's been that way since time immemorial, but I can no longer
recall whether it was initially done by intent.

And it's seen far less frequently nowadays. Back then we had a
general tendency to be a little more cavalier in such matters.

What, /ee? It's the normal way to get single variables interpolated.

A single /e is like an eval { }, and compiled at compile time.

A single /e just makes the rhs an expression with no ‘eval’ and no
block.

I was wrong about there being no block. There is a block in s///e, but
not in s//$a[...]/ with no /e.

I was using eval in the sense of "to evaluate an expression", not eval in
the sense of "to catch exceptions". I was trying to explain it with the
/e mnemonic always meaning eval, even though that risks confusion about
what happens whether exceptions are caught.

0\. s/PATTERN/QQ\_STRING/;              
1\. s/PATTERN/          EXPR/e;    \# no catch
2\. s/PATTERN/     EVAL EXPR/ee;   \# yes catch
3\. s/PATTERN/EVAL EVAL EXPR/eee;  \# yes catch
    \(etc\.\)

In case 1, the replacement value is the result of evaluating EXPR.
EXPR was syntax-checked and compiled at compile time, and there is
no catching of exceptions.

I don't think it is forbidden to speak of evaluating expressions
at runtime. I'm not thrilled wtih trying to explain that it's
really do{EXPR} intead of eval{EXPR}. One evaluates expressions;
what better word would you suggest there?

‘Evaluate’ is fine, but don’t call it ‘eval’, as that refers to Perl’s
error-catching keyword.

A double /e is more like an eval "", and gets compiled at run time.

But I never much go beyond that, because that's writing
eval eval foo().

And the number of evals is one less than the number of e’s.

The number of evaluations is equal to the number of e’s.

--tom

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Feb 12, 2012

From @cpansprout

On Sun Feb 05 09​:55​:52 2012, demerphq wrote​:

Is it, it seems like it warns, which would be a deliberate action, so
I can only assume it is a feature.

The re pragma has always warned about invalid flags, rather than
croaking. ‘use re "/a"’ has always been valid (with a warning as of
5.8), and I wasn’t going to break that.

$ perl5.6.2 -e 'use re "/a"'
$ perl5.8.1 -e 'use re "/a"'
Unknown "re" subpragma '/a' (known ones are​: 'debug', 'debugcolor',
'eval', 'taint') at -e line 1

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Feb 12, 2012

From @cpansprout

On Sun Feb 05 10​:28​:38 2012, tom christiansen wrote​:

Also, all four (or five) of the flaggy PYOQ pseudofuncs can be found
using the =~ operator. Yes, even qr//,

qr// is allowed on the rhs of =~ simply because arbitrary expressions
are allowed there. Other invexillar pyoq ops can go there too, as in
"a" =~ q/a/.

for all the good it'll do you.

It’s useful for working around bugs.

$u = ",echle etn sJ";
$t = "\nrka rPrhoatu";
$_ = $u.$t;
sub foo { s/(.)//s or return; bar(); print chop $$1 }
sub bar { s/(.)//s or return; foo(); print chop $$1 }
foo

That example uses substitution, so the workaround is my $qr = qr/(.)/
and later s/$qr//s. But in cases where m// is used without g or c qr//
is a non-buggy drop-in replacement.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Feb 3, 2013

From @jkeenan

On Sun Feb 12 11​:33​:28 2012, sprout wrote​:

On Sun Feb 05 10​:28​:38 2012, tom christiansen wrote​:

Also, all four (or five) of the flaggy PYOQ pseudofuncs can be found
using the =~ operator. Yes, even qr//,

qr// is allowed on the rhs of =~ simply because arbitrary expressions
are allowed there. Other invexillar pyoq ops can go there too, as in
"a" =~ q/a/.

for all the good it'll do you.

It’s useful for working around bugs.

$u = ",echle etn sJ";
$t = "\nrka rPrhoatu";
$_ = $u.$t;
sub foo { s/(.)//s or return; bar(); print chop $$1 }
sub bar { s/(.)//s or return; foo(); print chop $$1 }
foo

That example uses substitution, so the workaround is my $qr = qr/(.)/
and later s/$qr//s. But in cases where m// is used without g or c qr//
is a non-buggy drop-in replacement.

Discussion in this RT petered out about 12 months ago.

Is there still a bug in Perl which needs addressing?

Thank you very much.
Jim Keenan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants