Skip to content

pod and comments: Note escape vs quote #23264

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

Open
wants to merge 3 commits into
base: blead
Choose a base branch
from

Conversation

khwilliamson
Copy link
Contributor

Fixes #15221

The documentation and comments was misleading about conflating quoting a metacharacter and escaping it. Since \Q stands for quote, we have to continue to use that terminology. This commit clarifies that the two terms are often equivalent.

  • This set of changes does not require a perldelta entry.

@khwilliamson khwilliamson force-pushed the escape branch 2 times, most recently from ede7f9d to 8d8d490 Compare May 6, 2025 14:56
pod/perlre.pod Outdated
Today it is more common to use the C<L<quotemeta()|perlfunc/quotemeta>>
(If C<use locale> is in effect, then this depends on the current locale.)

This template used to be a common paradigm, but these days it is more
Copy link
Contributor

@Grinnz Grinnz May 7, 2025

Choose a reason for hiding this comment

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

It's not really the purpose of this PR, but I think it's a little misleading to say that quotemeta "disables metacharacters special meanings" without also saying that it actually does a very similar thing to the example just above, without being locale dependent for ASCII characters. i.e. it's exactly equivalent to s/([^A-Za-z_0-9])/\\$1/g or s/(\W)/\\$1/ag for ASCII characters (with behavior on non-ASCII characters dependent on the unicode_strings feature).

Copy link
Contributor

Choose a reason for hiding this comment

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

With the additional very useful feature that it can be interpolated with \Q and \E rather than applied to the whole pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Grinnz please check if new wording is ok

Copy link
Contributor

@Grinnz Grinnz left a comment

Choose a reason for hiding this comment

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

Otherwise I think this is an excellent improvement

Copy link
Contributor

@jkeenan jkeenan left a comment

Choose a reason for hiding this comment

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

I'm generally in favor of the changes presented in this p.r. But there is a lot in it, and I'd particularly like extra eyeballs on the changes in pod/perlre.pod.

pod/perlre.pod Outdated

quotemeta $pattern;

does either of these:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not quite sure this is correct, it's not quite how the quotemeta docs describe it, but it sounds complex. In particular it says that ASCII characters are always subject to the ASCII style escaping regardless of unicode_strings or the utf8 flag. Maybe better to say it does similar things, give the basics, and link to the quotemeta docs for details.

This adds a bit of text about metacharacters that was missing from this
introductory pod.
Fixes Perl#15221

The documentation and comments were misleading about conflating quoting
a metacharacter and escaping it.  Since \Q stands for quote, we have to
continue to use that terminology.  This commit clarifies that the two
terms are often equivalent.

This also adds detail about quotemeta and \Q.
By adding a word to a =heading, a sentence can be removed, and is
clearer.

But since some pod somewhere  may link to that heading, a section at the
end is added with the old name, and pointing to the new one.

Dan Book searched and found no instances in CPAN of the old heading
being linked to, but this guarantees that nothing breaks.
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.

Misuse of "quote" in place of "escape" in documentation
4 participants