Skip to content

regex pod fixes related to /p as it stands today - #24554

Open
demerphq wants to merge 1 commit into
bleadfrom
yves/fix_docs_for_keepcopy_regex_modifer_p
Open

regex pod fixes related to /p as it stands today#24554
demerphq wants to merge 1 commit into
bleadfrom
yves/fix_docs_for_keepcopy_regex_modifer_p

Conversation

@demerphq

Copy link
Copy Markdown
Collaborator

This documentation patch updates the docs to explain when and where /p is still relevent, and documents the performance reasons why. For a long time the docs have been incorrectly stating /p is not used or relevant anymore and that COW has made it redundant. This is unfortunately not the case, and it is still relevant for /g matches where the target string is not copied. Its a weird edge case, I bet no-one cares or actually needs it, but because of the flaws in our COW model we would make some code quadratic out of the box by making scalar /g matches copy the target string. As such we need an escape hatch for when the user wants to override that for some reason.

I am inclined to think that removing PL_saw_ampersand was premature as well, COW isnt a complete solution for the performance issues that PL_saw_ampersand was solving.

  • This set of changes does not require a perldelta entry, but one is included anyway to call peoples attention to it.

This documentation patch updates the docs to explain when and where
/p is still relevent, and documents the performance reasons why. For
a long time the docs have been incorrectly stating /p is not used or
relevant anymore and that COW has made it redundant. This is
unfortunately not the case, and it is still relevant for /g matches
where the target string is not copied. Its a weird edge case, I bet
no-one cares or actually needs it, but because of the flaws in our
COW model we would make some code quadratic out of the box by making
scalar /g matches copy the target string. As such we need an escape
hatch for when the user wants to override that for some reason.

I am inclined to think that removing PL_saw_ampersand was premature
as well, COW isnt a complete solution for the performance issues that
PL_saw_ampersand was solving.
@demerphq
demerphq requested a review from book July 11, 2026 09:35
@haarg

haarg commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

This is a follow up on #20728 and #20931, since the previous doc fix missed some parts.

Comment thread pod/perlop.pod
They do not simply rely on copy-on-write for that, since copy-on-write
sharing is bounded and some target strings cannot use it. Use C</p> if
you need C<${^PREMATCH}>, C<${^MATCH}>, or C<${^POSTMATCH}> after such a
match.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found "such" confusing. I think this means that if you need any one of the variables, add /p, but it kind of sounded like, "if you have bad experience, add /p"

@leonerd leonerd added the defer-next-dev This PR should not be merged yet, but await the next development cycle label Jul 13, 2026
@book

book commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

This is also related to #24147.

@book book left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Nice to learn about the limitations of copy-on-write.

@book

book commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@Leont: Since this is just a doc patch, why not ship it with 5.44?

@leonerd leonerd removed the defer-next-dev This PR should not be merged yet, but await the next development cycle label Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants