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

${^MATCH} not set without /p (contrary to docs) #15938

Closed
p5pRT opened this issue Apr 1, 2017 · 10 comments
Closed

${^MATCH} not set without /p (contrary to docs) #15938

p5pRT opened this issue Apr 1, 2017 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Apr 1, 2017

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

Searchable as RT131087$

@p5pRT
Copy link
Author

p5pRT commented Apr 1, 2017

From @ikegami

Created by @ikegami

perlre says​:

p

Preserve the string matched such that ${^PREMATCH} , ${^MATCH} , and
${^POSTMATCH} are available for use after matching.

In Perl 5.20 and higher this is ignored. Due to a new copy-on-write
mechanism, ${^PREMATCH} , ${^MATCH} , and ${^POSTMATCH} will be
available after the match regardless of the modifier.

perlvar says​:

${^MATCH}

This is similar to $& ($MATCH ) except that it does not incur the
performance penalty associated with that variable.

In Perl v5.18 and earlier, it is only guaranteed to return a defined
value when the pattern was compiled or executed with the /p modifier.
In Perl v5.20, the /p modifier does nothing, so ${^MATCH} does the same
thing as $MATCH .

test (without /p)

  echo 'Lorem ipsum dolor sit ut dicta qui dolores.' |\
  perl -nE 'say "$&|${^MATCH}" while m/dolor/g'

output​:

  dolor|
  dolor|

test (with /p)​:

  echo 'Lorem ipsum dolor sit ut dicta qui dolores.' |\
  perl -nE 'say ${^MATCH} while m/dolor/gp'

output​:

  dolor|dolor
  dolor|dolor

The code's behaviour differs from both perlre and perlvar.

- Eric

In reference to
http​://stackoverflow.com/questions/43159304/the-match-and-the-p-modifier-in-perl-v24

Sorry if you have received this twice.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.24.0:

Configured by ikegami at Wed May 25 21:22:43 PDT 2016.

Summary of my perl5 (revision 5 version 24 subversion 0) configuration:

  Platform:
    osname=linux, osvers=3.2.61-grsec-modsign,
archname=x86_64-linux-thread-multi
    uname='linux springfield 3.2.61-grsec-modsign #1 smp tue aug 12
09:58:26 utc 2014 x86_64 x86_64 x86_64 gnulinux '
    config_args='-de -Dprefix=/home/ikegami/usr/perlbrew/perls/5.24.0t
-DPERL_SUB_DEPTH_WARN=1000 -Dusethreads
-Aeval:scriptdir=/home/ikegami/usr/perlbrew/perls/5.24.0t/bin'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv
-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.6.3', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678,
doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16,
longdblkind=3
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
/usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib
/usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
-lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.15.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.15'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib
-fstack-protector'



@INC for perl 5.24.0:

/home/ikegami/usr/perlbrew/perls/5.24.0t/lib/site_perl/5.24.0/x86_64-linux-thread-multi
    /home/ikegami/usr/perlbrew/perls/5.24.0t/lib/site_perl/5.24.0

/home/ikegami/usr/perlbrew/perls/5.24.0t/lib/5.24.0/x86_64-linux-thread-multi
    /home/ikegami/usr/perlbrew/perls/5.24.0t/lib/5.24.0
    .


Environment for perl 5.24.0:
    HOME=/home/ikegami
    LANG (unset)
    LANGUAGE (unset)
    LC_COLLATE=C
    LD_LIBRARY_PATH=/home/ikegami/lib
    LOGDIR (unset)

PATH=/home/ikegami/usr/perlbrew/bin:/home/ikegami/usr/perlbrew/perls/latest/bin:.:/home/ikegami/bin:/home/ikegami/.gems/bin:/usr/lib/ruby/gems/1.8/bin/:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
    PERLBREW_BASHRC_VERSION=0.71
    PERLBREW_HOME=/home/ikegami/.perlbrew
    PERLBREW_MANPATH=/home/ikegami/usr/perlbrew/perls/latest/man

PERLBREW_PATH=/home/ikegami/usr/perlbrew/bin:/home/ikegami/usr/perlbrew/perls/latest/bin
    PERLBREW_PERL=latest
    PERLBREW_ROOT=/home/ikegami/usr/perlbrew
    PERLBREW_VERSION=0.71
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Apr 1, 2017

From @ikegami

On Sat, 01 Apr 2017 14​:34​:32 -0700, ikegami@​adaelis.com wrote​:

test (with /p)​:

echo 'Lorem ipsum dolor sit ut dicta qui dolores.' |\
perl -nE 'say ${^MATCH} while m/dolor/gp'

output​:

dolor|dolor
dolor|dolor

Actual code run​:

  echo 'Lorem ipsum dolor sit ut dicta qui dolores.' |\
  perl -nE 'say "$&|${^MATCH}" while m/dolor/gp'

@p5pRT
Copy link
Author

p5pRT commented Jun 13, 2017

From @jkeenan

On Sat, 01 Apr 2017 21​:34​:32 GMT, ikegami@​adaelis.com wrote​:

This is a bug report for perl from ikegami@​adaelis.com,
generated with the help of perlbug 1.40 running under perl 5.24.0.

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

perlre says​:

p

Preserve the string matched such that ${^PREMATCH} , ${^MATCH} , and
${^POSTMATCH} are available for use after matching.

In Perl 5.20 and higher this is ignored. Due to a new copy-on-write
mechanism, ${^PREMATCH} , ${^MATCH} , and ${^POSTMATCH} will be
available after the match regardless of the modifier.

perlvar says​:

${^MATCH}

This is similar to $& ($MATCH ) except that it does not incur the
performance penalty associated with that variable.

In Perl v5.18 and earlier, it is only guaranteed to return a defined
value when the pattern was compiled or executed with the /p modifier.
In Perl v5.20, the /p modifier does nothing, so ${^MATCH} does the
same
thing as $MATCH .

test (without /p)

echo 'Lorem ipsum dolor sit ut dicta qui dolores.' |\
perl -nE 'say "$&|${^MATCH}" while m/dolor/g'

output​:

dolor|
dolor|

test (with /p)​:

echo 'Lorem ipsum dolor sit ut dicta qui dolores.' |\
perl -nE 'say ${^MATCH} while m/dolor/gp'

output​:

dolor|dolor
dolor|dolor

The code's behaviour differs from both perlre and perlvar.

- Eric

In reference to
http​://stackoverflow.com/questions/43159304/the-match-and-the-p-
modifier-in-perl-v24

I'm not getting the same output as you reported.

#####
$ perl -v | head -2 | tail -1
This is perl 5, version 26, subversion 0 (v5.26.0) built for x86_64-linux

$ echo 'Lorem ipsum dolor sit ut dicta qui dolores.' | perl -nE 'say ${^MATCH} while m/dolor/gp'
dolor
dolor

$ echo 'Lorem ipsum dolor sit ut dicta qui dolores.' | perl -nE 'say ${^MATCH} while m/dolor/g'

$ perlbrew use perl-5.18.4

$ perl -v | head -2 | tail -1
This is perl 5, version 18, subversion 4 (v5.18.4) built for x86_64-linux

$ echo 'Lorem ipsum dolor sit ut dicta qui dolores.' | perl -nE 'say ${^MATCH} while m/dolor/gp'
dolor
dolor

$ echo 'Lorem ipsum dolor sit ut dicta qui dolores.' | perl -nE 'say ${^MATCH} while m/dolor/g'

#####

What am I missing?

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Jun 13, 2017

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

@p5pRT
Copy link
Author

p5pRT commented Jun 13, 2017

From @ikegami

You are getting the same incorrect output as I am.

On Tue, Jun 13, 2017 at 3​:29 PM, James E Keenan via RT <
perlbug-followup@​perl.org> wrote​:

On Sat, 01 Apr 2017 21​:34​:32 GMT, ikegami@​adaelis.com wrote​:

This is a bug report for perl from ikegami@​adaelis.com,
generated with the help of perlbug 1.40 running under perl 5.24.0.

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

perlre says​:

p

Preserve the string matched such that ${^PREMATCH} , ${^MATCH} , and
${^POSTMATCH} are available for use after matching.

In Perl 5.20 and higher this is ignored. Due to a new copy-on-write
mechanism, ${^PREMATCH} , ${^MATCH} , and ${^POSTMATCH} will be
available after the match regardless of the modifier.

perlvar says​:

${^MATCH}

This is similar to $& ($MATCH ) except that it does not incur the
performance penalty associated with that variable.

In Perl v5.18 and earlier, it is only guaranteed to return a defined
value when the pattern was compiled or executed with the /p modifier.
In Perl v5.20, the /p modifier does nothing, so ${^MATCH} does the
same
thing as $MATCH .

test (without /p)

echo 'Lorem ipsum dolor sit ut dicta qui dolores.' |\
perl -nE 'say "$&|${^MATCH}" while m/dolor/g'

output​:

dolor|
dolor|

test (with /p)​:

echo 'Lorem ipsum dolor sit ut dicta qui dolores.' |\
perl -nE 'say ${^MATCH} while m/dolor/gp'

output​:

dolor|dolor
dolor|dolor

The code's behaviour differs from both perlre and perlvar.

- Eric

In reference to
http​://stackoverflow.com/questions/43159304/the-match-and-the-p-
modifier-in-perl-v24

I'm not getting the same output as you reported.

#####
$ perl -v | head -2 | tail -1
This is perl 5, version 26, subversion 0 (v5.26.0) built for x86_64-linux

$ echo 'Lorem ipsum dolor sit ut dicta qui dolores.' | perl -nE 'say
${^MATCH} while m/dolor/gp'
dolor
dolor

$ echo 'Lorem ipsum dolor sit ut dicta qui dolores.' | perl -nE 'say
${^MATCH} while m/dolor/g'

$ perlbrew use perl-5.18.4

$ perl -v | head -2 | tail -1
This is perl 5, version 18, subversion 4 (v5.18.4) built for x86_64-linux

$ echo 'Lorem ipsum dolor sit ut dicta qui dolores.' | perl -nE 'say
${^MATCH} while m/dolor/gp'
dolor
dolor

$ echo 'Lorem ipsum dolor sit ut dicta qui dolores.' | perl -nE 'say
${^MATCH} while m/dolor/g'

#####

What am I missing?

--
James E Keenan (jkeenan@​cpan.org)

---
via perlbug​: queue​: perl5 status​: new
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=131087

@p5pRT
Copy link
Author

p5pRT commented Jun 14, 2017

From @Abigail

On Sat, Apr 01, 2017 at 02​:34​:33PM -0700, Eric Brine wrote​:

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

This is a bug report for perl from ikegami@​adaelis.com,
generated with the help of perlbug 1.40 running under perl 5.24.0.

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

perlre says​:

p

Preserve the string matched such that ${^PREMATCH} , ${^MATCH} , and
${^POSTMATCH} are available for use after matching.

In Perl 5.20 and higher this is ignored. Due to a new copy-on-write
mechanism, ${^PREMATCH} , ${^MATCH} , and ${^POSTMATCH} will be
available after the match regardless of the modifier.

perlvar says​:

${^MATCH}

This is similar to $& ($MATCH ) except that it does not incur the
performance penalty associated with that variable.

In Perl v5.18 and earlier, it is only guaranteed to return a defined
value when the pattern was compiled or executed with the /p modifier.
In Perl v5.20, the /p modifier does nothing, so ${^MATCH} does the same
thing as $MATCH .

test (without /p)

echo 'Lorem ipsum dolor sit ut dicta qui dolores\.' |\\
 perl \-nE 'say "$&|$\{^MATCH\}" while m/dolor/g'

output​:

dolor|
dolor|

test (with /p)​:

echo 'Lorem ipsum dolor sit ut dicta qui dolores\.' |\\
 perl \-nE 'say $\{^MATCH\} while m/dolor/gp'

output​:

dolor|dolor
dolor|dolor

The code's behaviour differs from both perlre and perlvar.

The lines in the documentation were added by the following commit​:

commit 13b0f67
Author​: David Mitchell <davem@​iabyn.com>
Date​: Wed May 22 16​:38​:29 2013 +0100

  re-enable Copy-on-Write by default.
 
  COW was first introduced (and enabled by default) in 5.17.7.
  It was disabled by default in 5.17.10, because it was though to have too
  many rough edges for the 5.18.0 release.
 
  By re-enabling it now, early in the 5.19.x release cycle, hopefully it
  will be ready for production use by 5.20.
 
  This commit mainly reverts 9f351b4 and e1fd413 (with modifications),
  then updates perldelta.

I don't recall ever hearing that /p was ignored (or supposed to be
ignored) before.

Abigail

@p5pRT
Copy link
Author

p5pRT commented Jun 16, 2017

From @iabyn

On Wed, Jun 14, 2017 at 12​:21​:09PM +0200, Abigail wrote​:

The lines in the documentation were added by the following commit​:

commit 13b0f67
Author​: David Mitchell <davem@​iabyn.com>
Date​: Wed May 22 16​:38​:29 2013 +0100

re\-enable Copy\-on\-Write by default\.

That commit was merely re-applying COW changes which had been temporarily
reverted. The text was originally added by this commit [he says, throwing
the buck as far as it will fly]​:

  commit d78f32f
  Author​: Father Chrysostomos <sprout@​cpan.org>
  AuthorDate​: Sun Nov 25 14​:50​:48 2012 -0800
  Commit​: Father Chrysostomos <sprout@​cpan.org>
  CommitDate​: Tue Nov 27 07​:05​:04 2012 -0800

  Update docs to concur with $`,$&amp;,$' changes
 
  plus a couple of other pod tweaks.

--
I thought I was wrong once, but I was mistaken.

@p5pRT
Copy link
Author

p5pRT commented Jun 17, 2017

From @demerphq

On 16 June 2017 at 14​:58, Dave Mitchell <davem@​iabyn.com> wrote​:

On Wed, Jun 14, 2017 at 12​:21​:09PM +0200, Abigail wrote​:

The lines in the documentation were added by the following commit​:

commit 13b0f67
Author​: David Mitchell <davem@​iabyn.com>
Date​: Wed May 22 16​:38​:29 2013 +0100

re\-enable Copy\-on\-Write by default\.

That commit was merely re-applying COW changes which had been temporarily
reverted. The text was originally added by this commit [he says, throwing
the buck as far as it will fly]​:

commit d78f32f607952d58a998c5b7554572320dc57b2a
Author&#8203;:     Father Chrysostomos \<sprout@&#8203;cpan\.org>
AuthorDate&#8203;: Sun Nov 25 14&#8203;:50&#8203;:48 2012 \-0800
Commit&#8203;:     Father Chrysostomos \<sprout@&#8203;cpan\.org>
CommitDate&#8203;: Tue Nov 27 07&#8203;:05&#8203;:04 2012 \-0800

Update docs to concur with $\`\,$&\,$' changes

plus a couple of other pod tweaks\.

There was some discussion of reverting some of this as COW does not
reliably solve the problem that lead to /p. Your new COW proposals I
believe, or the ones I proposed before that, should resolve this.

I may even have made changes to some of this infrastructure due to
this. I dont remember. I will try to check later.

cheers,
Yves

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

@khwilliamson
Copy link
Contributor

@demerphq any progress?

@demerphq
Copy link
Collaborator

No sorry, this got lost in the chaos caused by some traumatic personal events. I can try to take a look. But I make no promises ill have a fix in time for the 20th.

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

5 participants