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
[PATCH] addition to perlrecharclass about '$' as "special" #15601
Comments
From cpan@goess.orgCreated by cpan@goess.orgI'm suggesting a documentation change. perlrecharclass says "Most characters [$,] and it would be good advice to point out that a '$' is as special inside a Perl Info
|
From cpan@goess.org0001-adding-note-re-in-character-classes.patchFrom bcda3765acb6e782fac719483de50b4ab51ab13b Mon Sep 17 00:00:00 2001
From: "Kevin M. Goess" <cpan@goess.org>
Date: Thu, 15 Sep 2016 11:19:06 -0700
Subject: [PATCH] adding note re '$' in character classes
It would be helpful to know that a $ in a character class really *does* want to
be escaped, unless you really do intend to refer to the perl special variable
whose name you've happened to create. Which is to say:
[$!]
should probably really be
[\$!]
---
pod/perlrecharclass.pod | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/pod/perlrecharclass.pod b/pod/perlrecharclass.pod
index 89f4a7e..61c8b3a 100644
--- a/pod/perlrecharclass.pod
+++ b/pod/perlrecharclass.pod
@@ -543,6 +543,12 @@ bracketed character class.
Also, a backslash followed by two or three octal digits is considered an octal
number.
+A C<$> is just as special in a character class as it is anywhere else in a
+regular expression: if it's not marking the end of a pattern then it's the
+sigil for a perl variable. So the class C<[$?]> actually interpolates to this
+C<[0]> or whatever the current value of your $CHILD_ERROR special variable
+happens to be.
+
A C<[> is not special inside a character class, unless it's the start of a
POSIX character class (see L</POSIX Character Classes> below). It normally does
not need escaping.
--
1.8.3.1
|
From @jkeenanOn Thu Sep 15 11:34:02 2016, cpan@goess.org wrote:
While I agree with the general thrust of the patch, I think we're going to have to brainstorm for edge cases before we nail down its final wording. Consider the following: ##### { __END__ Output: ##### Is that the output we all expect? How do we describe the behavior of the "dollar-variables" inside negated character classes? Thank you very much. -- |
The RT System itself - Status changed from 'new' to 'open' |
From @maukeAm 15.09.2016 um 20:34 schrieb Kevin Goess (via RT):
It will if you use it in m'...', as in m'[$,]'. -- |
From @AbigailOn Thu, Sep 15, 2016 at 11:34:02AM -0700, Kevin Goess wrote:
But it does: $ perl -wE 'say q{$} =~ q{[$,]}'
Now, if you use delimiters which allow for interpolation of variables, Abigail |
From @khwilliamsonOn Thu Sep 15 16:13:23 2016, abigail@abigail.be wrote:
How about the attached patch instead? -- |
From @khwilliamson0001-alternate-patch-for-129277.patchFrom a6b63f4e4781c3ae0a4dc1e4ae0eedd98bb7e781 Mon Sep 17 00:00:00 2001
From: Karl Williamson <khw@cpan.org>
Date: Thu, 15 Sep 2016 21:52:44 -0600
Subject: [PATCH] alternate patch for 129277
---
pod/perlrecharclass.pod | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/pod/perlrecharclass.pod b/pod/perlrecharclass.pod
index 89f4a7e..51ad3db 100644
--- a/pod/perlrecharclass.pod
+++ b/pod/perlrecharclass.pod
@@ -512,7 +512,13 @@ is, characters that carry a special meaning like C<.>, C<*>, or C<(>) lose
their special meaning and can be used inside a character class without
the need to escape them. For instance, C<[()]> matches either an opening
parenthesis, or a closing parenthesis, and the parens inside the character
-class don't group or capture.
+class don't group or capture. Beware that, unless the pattern is
+enclosed in single-quotes, variable interpolation will take place before
+the bracketed class is parsed:
+
+ $, = "\t| ";
+ $a =~ m'[$,]'; # single-quotish: matches '$' or ','
+ $a =~ m/[$,]/; # double-quotish: matches "\t", "|", or " "
Characters that may carry a special meaning inside a character class are:
C<\>, C<^>, C<->, C<[> and C<]>, and are discussed below. They can be
--
2.7.4
|
From @khwilliamsonOr this slightly improved version? |
From @khwilliamson0001-alternate-patch-for-129277.patchFrom 8828f70c81bbe6d7af0213f6345831c120b72ad9 Mon Sep 17 00:00:00 2001
From: Karl Williamson <khw@cpan.org>
Date: Thu, 15 Sep 2016 21:52:44 -0600
Subject: [PATCH] alternate patch for 129277
---
pod/perlrecharclass.pod | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/pod/perlrecharclass.pod b/pod/perlrecharclass.pod
index 89f4a7e..89a481c 100644
--- a/pod/perlrecharclass.pod
+++ b/pod/perlrecharclass.pod
@@ -512,7 +512,14 @@ is, characters that carry a special meaning like C<.>, C<*>, or C<(>) lose
their special meaning and can be used inside a character class without
the need to escape them. For instance, C<[()]> matches either an opening
parenthesis, or a closing parenthesis, and the parens inside the character
-class don't group or capture.
+class don't group or capture. Beware that, unless the pattern is
+evaluated in single-quotish context, variable interpolation will take
+place before the bracketed class is parsed:
+
+ $, = "\t| ";
+ $a =~ m'[$,]'; # single-quotish: matches '$' or ','
+ $a =~ q{[$,]}' # same
+ $a =~ m/[$,]/; # double-quotish: matches "\t", "|", or " "
Characters that may carry a special meaning inside a character class are:
C<\>, C<^>, C<->, C<[> and C<]>, and are discussed below. They can be
--
2.7.4
|
From [Unknown Contact. See original ticket]Or this slightly improved version? |
From kevin@goess.orgInstead of "beware that" I might say "be aware that", but otherwise it On Mon, Oct 17, 2016 at 7:44 PM, Karl Williamson via RT <
|
From @khwilliamsonIn the absence of further comment, I changed it to 'Be aware', and applied it as |
@khwilliamson - Status changed from 'open' to 'pending release' |
From @khwilliamsonOn Wed Oct 26 10:35:42 2016, khw wrote:
Oops, the commit really was -- |
From @AbigailOn Mon, Oct 17, 2016 at 07:44:39PM -0700, Karl Williamson via RT wrote:
Looks good to me. Abigail |
From @khwilliamsonThank you for filing this report. You have helped make Perl better. With the release today of Perl 5.26.0, this and 210 other issues have been Perl 5.26.0 may be downloaded via: If you find that the problem persists, feel free to reopen this ticket. |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#129277 (status was 'resolved')
Searchable as RT129277$
The text was updated successfully, but these errors were encountered: