Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.96k stars 555 forks source link

Oddity of /p #11710

Open p5pRT opened 13 years ago

p5pRT commented 13 years ago

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

Searchable as RT101938$

p5pRT commented 13 years ago

From @ikegami

Created by @ikegami

This is a bug report for perl from ikegami@​adaelis.com\, generated with the help of perlbug 1.39 running under perl 5.14.0. -----------------------------------------------------------------

Hi\,

Does the "p" modifier apply to the operator (like "o") or the pattern (like "s")? It seems to me it applies to the operator.

That said\, (?​:) supports p\, although it has no effect (sometimes with warning\, sometimes without).

perl -wE"'x' =~ /x/p or die; say ${^MATCH} // '-';" x

perl -wE"'x' =~ /(?p​:x)/ or die; say ${^MATCH} // '-';" -

perl -wE"'x' =~ /(?-p​:x)/p or die; say ${^MATCH} // '-';" Useless use of (?-p) in regex; marked by \<-- HERE in m/(?-p \<-- HERE :x)/ at -e line 1. x

Except sometimes it does have an effect.

perl -wE"$re=qr/x/p; 'x' =~ /${re}/ or die; say ${^MATCH} // '-';" x

perl -wE"$re=qr/x/p; 'xy' =~ /${re}y/ or die; say ${^MATCH} // '-';" -

And then there's the case where (?-p​:) warns even though it appears to work.

perl -wE"$re=qr/x/p; 'x' =~ /$re/ or die; say ${^MATCH} // '-';" x

perl -wE"$re=qr/x/p; 'x' =~ /(?-p​:$re)/ or die; say ${^MATCH} // '-';" Useless use of (?-p) in regex; marked by \<-- HERE in m/(?-p \<-- HERE :(?^up​:x))/ at -e line 1. -

From a user's perspective\, none of this makes no sense. It was probably done this way so C\<\< $re = qr/.../p; $_ =~ $re >> works\, but that doesn't really make sense either. "p" should be a m// modifier\, it shouldn't be qr// modifier\, and it should be allowed in (?​:).

- Eric

Perl Info ``` Flags: category=core severity=low Site configuration information for perl 5.14.0: Configured by gecko at Thu May 12 09:33:39 2011. Summary of my perl5 (revision 5 version 14 subversion 0) configuration: Platform: osname=MSWin32, osvers=5.2, archname=MSWin32-x86-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=undef, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='C:/Progs/PERL51~4/site/bin/gcc.exe', ccflags ='-DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DPERL_TEXTMODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -D_USE_32BIT_TIME_T -DHASATTRIBUTE -fno-strict-aliasing -mms-bitfields', optimize='-O2', cppflags='-DWIN32' ccversion='', gccversion='3.4.5 (mingw-vista special r3)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='C:\Progs\PERL51~4\site\bin\g++.exe', ldflags ='-L"C:\Progs\perl5140-ap1400\lib\CORE"' libpth=\lib libs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 -lmsvcrt perllibs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 -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:\Progs\perl5140-ap1400\lib\CORE"' Locally applied patches: ACTIVEPERL_LOCAL_PATCHES_ENTRY @INC for perl 5.14.0: C:/Progs/perl5140-ap1400/site/lib C:/Progs/perl5140-ap1400/lib . Environment for perl 5.14.0: HOME (unset) LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=c:\bin;C:\Progs\perl5140-ap1400\site\bin;C:\Progs\perl5140-ap1400\bin;... PERL_BADLANG (unset) SHELL (unset) ```
p5pRT commented 13 years ago

From @ikegami

On Fri Oct 21 21​:08​:11 2011\, ikegami@​adaelis.com wrote​:

"p" should be a m// modifier\, it shouldn't be qr// modifier\, and it should be allowed in (?​:).

doh! I meant

"p" should be a m// modifier\, it shouldn't be qr// modifier\, and it *shouldn't* be allowed in (?​:).

p5pRT commented 13 years ago

@ikegami - Status changed from 'new' to 'open'

p5pRT commented 13 years ago

From @cpansprout

On Fri Oct 21 21​:08​:11 2011\, ikegami@​adaelis.com wrote​:

This is a bug report for perl from ikegami@​adaelis.com\, generated with the help of perlbug 1.39 running under perl 5.14.0. -----------------------------------------------------------------

Hi\,

Does the "p" modifier apply to the operator (like "o") or the pattern (like "s")? It seems to me it applies to the operator.

That said\, (?​:) supports p\, although it has no effect (sometimes with warning\, sometimes without).

perl -wE"'x' =~ /x/p or die; say ${^MATCH} // '-';" x

perl -wE"'x' =~ /(?p​:x)/ or die; say ${^MATCH} // '-';" -

perl -wE"'x' =~ /(?-p​:x)/p or die; say ${^MATCH} // '-';" Useless use of (?-p) in regex; marked by \<-- HERE in m/(?-p \<-- HERE :x)/ at -e line 1. x

Except sometimes it does have an effect.

perl -wE"$re=qr/x/p; 'x' =~ /${re}/ or die; say ${^MATCH} // '-';" x

perl -wE"$re=qr/x/p; 'xy' =~ /${re}y/ or die; say ${^MATCH} // '-';" -

And then there's the case where (?-p​:) warns even though it appears to work.

perl -wE"$re=qr/x/p; 'x' =~ /$re/ or die; say ${^MATCH} // '-';" x

perl -wE"$re=qr/x/p; 'x' =~ /(?-p​:$re)/ or die; say ${^MATCH} // '- ';" Useless use of (?-p) in regex; marked by \<-- HERE in m/(?-p \<-- HERE :(?^up​:x))/ at -e line 1. -

From a user's perspective\, none of this makes no sense.

I would say *all* of this makes no sense. :-)

It makes as much sense as $x = qr/foo/g; s/$x/bar/; (which\, come to think of it\, is just like JavaScript).

Notice I didn’t add /p support to ‘use re '/flags'’.

p5pRT commented 13 years ago

From @ikegami

On Sat\, Oct 22\, 2011 at 1​:22 AM\, Father Chrysostomos via RT \< perlbug-followup@​perl.org> wrote​:

From a user's perspective\, none of this makes no sense.

I would say *all* of this makes no sense. :-)

sigh\, I'm wearing my contacts for the first time in many months\, and apparently\, that's causing me to negate everything I say! X_X

Yes\, that's what I meant\, thanks.

p5pRT commented 13 years ago

From @abigail

On Fri\, Oct 21\, 2011 at 09​:08​:11PM -0700\, Eric Brine wrote​:

# New Ticket Created by "Eric Brine" # Please include the string​: [perl #101938] # in the subject line of all future correspondence about this issue. # \<URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=101938 >

This is a bug report for perl from ikegami@​adaelis.com\, generated with the help of perlbug 1.39 running under perl 5.14.0. -----------------------------------------------------------------

Hi\,

Does the "p" modifier apply to the operator (like "o") or the pattern (like "s")? It seems to me it applies to the operator.

That said\, (?​:) supports p\, although it has no effect (sometimes with warning\, sometimes without).

perl -wE"'x' =~ /x/p or die; say ${^MATCH} // '-';" x

perl -wE"'x' =~ /(?p​:x)/ or die; say ${^MATCH} // '-';" -

perl -wE"'x' =~ /(?-p​:x)/p or die; say ${^MATCH} // '-';" Useless use of (?-p) in regex; marked by \<-- HERE in m/(?-p \<-- HERE :x)/ at -e line 1. x

Except sometimes it does have an effect.

perl -wE"$re=qr/x/p; 'x' =~ /${re}/ or die; say ${^MATCH} // '-';" x

perl -wE"$re=qr/x/p; 'xy' =~ /${re}y/ or die; say ${^MATCH} // '-';" -

That can be explained by the fact that /${re}/ doesn't do a stringification-regexp compile roundtrip\, where /${re}y/ does. It's a side-effect of the optimization.

And then there's the case where (?-p​:) warns even though it appears to work.

perl -wE"$re=qr/x/p; 'x' =~ /$re/ or die; say ${^MATCH} // '-';" x

perl -wE"$re=qr/x/p; 'x' =~ /(?-p​:$re)/ or die; say ${^MATCH} // '-';" Useless use of (?-p) in regex; marked by \<-- HERE in m/(?-p \<-- HERE :(?^up​:x))/ at -e line 1. -

Again\, that's due to the stringification-regexp compile roundtrip. Replacing (?-p by (?-i makes it print '-' as well.

From a user's perspective\, none of this makes no sense. It was probably done this way so C\<\< $re = qr/.../p; $_ =~ $re >> works\, but that doesn't really make sense either. "p" should be a m// modifier\, it shouldn't be qr// modifier\, and it should be allowed in (?​:).

Abigail

p5pRT commented 13 years ago

From @ikegami

On Sat\, Oct 22\, 2011 at 10​:45 AM\, Abigail \abigail@&#8203;abigail\.be wrote​:

That can be explained by the fact that /${re}/ doesn't do a stringification-regexp compile roundtrip\, where /${re}y/ does. It's a side-effect of the optimization.

Explain to whom? To me? I know that. To the users? I could be wrong\, but I don't think they care.