Re: [Perl/perl5] 502da7: make /p a no-op
[email protected] ("Philippe Bruhat (BooK)") Thu, 12 Feb 2026 16:36:29 +0100
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
Hi,
On Thu, Feb 12, 2026 at 06:00:35PM +0800, demerphq wrote:
> On my phone so forgive the double reply. The code i mean is something like
> this:
>
> while (<>) {
> while (/(.)/g) { $count++}
> }
>
> Try that on a large file. If it appears to hang then /p should not be
> removed.
Thanks Yves for bringing up this issue.
I tried this (also reported on the GitHub ticket):
$ time perl -E 'say $^V;while(<>){while(/(.)/g){$count++}}say$count' /tmp/big
v5.36.0
101876091
real 0m16.232s
user 0m16.208s
sys 0m0.020s
# this is the Perl built from https://github.com/Perl/perl5/pull/24191
$ time ./perl -Ilib -E 'say $^V;while(<>){while(/(.)/g){$count++}}say$count' /tmp/big
v5.43.8
101876091
real 0m48.173s
user 0m48.110s
sys 0m0.060s
So there's definitely a degradation.
> > Every time people proposed removing /p when I have checked while /g it
> > has been broken.
I'm a little bit confused about the whole $& vs ${^MATCH} situation.
The docs keep saying there was horrible degradation before 5.20, but
that everything is fixed since 5.20 and COW. And still things don't
appear as simple.
Is there a difference between the punctuation variables ($`, $& and $')
and the long name versions (${^PREMATCH}, ${^MATCH} and ${^POSTMATCH})?
What is it? And what is the relation with PL_sawampersand, which has
apparently been disabled since 1a904fc88069e249a4bd0ef196a3f1a7f549e0fe
in 2012?
Should we open an issue to completely remove the code related to
PL_sawampersand?
I've tried these in the hope of understanding the relationship
between the puncation variables and the long name ones:
# Using $& doesn't seem to make a difference
$ time perl -E 'say $^V;while(<>){while(/(.)/g){$&;$count++}}say$count' /tmp/big
v5.36.0
101876091
real 0m15.719s
user 0m15.705s
sys 0m0.013s
# Using /p and ${^MATCH} doesn't seem to make a difference either
$ time perl -E 'say $^V;while(<>){while(/(.)/gp){${^MATCH};$count++}}say$count' /tmp/big
v5.36.0
101876091
real 0m15.739s
user 0m15.723s
sys 0m0.017s
(Both of those suck like the first example with my patch bleadperl,
of course.)
In my limited understanding, the change I made (removing a conditional
goto) was equivalent to having /p always enabled. That doesn't seem to
be the actual result.
I'm clearly out of my depth here.
I started looking at this, because I believe that for PPC0014 (English
name aliases) to be complete, we want the caret long name match variables
to be simple aliases to the punctuation ones. Which I think means /p
must be a true no-op.
--
Philippe Bruhat (BooK)
Garbage that is well-wrapped is still garbage.
(Moral from Groo The Wanderer #64 (Epic))