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
underscore regex delimiters #9853
Comments
From chip@seas.upenn.eduCreated by chip@seas.upenn.eduSubstitutions don't work if the delimiter is the underscore character. $ perl -p -e 's#/32##;' Perl Info
|
From @rgs2009/8/26 chip@seas.upenn.edu (via RT) <perlbug-followup@perl.org>:
Hmm but _ is a word character. What if I have a function named |
The RT System itself - Status changed from 'new' to 'open' |
From zefram@fysh.orgchip@seas.upenn.edu (via RT) wrote:
The underscore is not perceived as a delimiter there, but as part of $ perl -MO=Deparse -e 's#/32##;' Other clues are available if you turn on warnings: $ perl -wce 's_/32__;' And if the substitution had contained other text then it would have $ perl -wce 's_\\__;' I believe the documentation is at fault. perlop(1) says: Any non-alphanumeric, non-whitespace delimiter may replace the Underscore is not alphanumeric or whitespace, but is evidently -zefram |
From @AbigailOn Thu, Aug 27, 2009 at 09:33:13AM +0100, Zefram wrote:
But even then, the documentation isn't correct. You *can* use word characters s _/32__ and s s/32ss are fine. The problem here lies in the tokenization part: the first token of In fact, this issue isn't any different from saying you cannot use C<< _ >> C<< func_ >> which isn't parsed as C<< func (_) >> either. Abigail |
From @demerphq2009/8/27 Abigail <abigail@abigail.be>:
The doocumentation should read "non-perl-word, non whitespace delimiter" We use "alphhanumeric" fairly regularly when we speak of
Right. This is not a bug. Cheers, -- |
From @nwc10On Thu, Aug 27, 2009 at 02:03:46PM +0200, demerphq wrote:
in the implementation. I think we agree that the documentation needs to be improved. Nicholas Clark |
From @davidnicol
Inline Patchdiff --git a/pod/perlop.pod b/pod/perlop.pod
index 0170202..26d0f1e 100644
--- a/pod/perlop.pod
+++ b/pod/perlop.pod
@@ -1167,11 +1167,13 @@ process modifiers are available:
c Do not reset search position on a failed match when /g is in effect.
If "/" is the delimiter then the initial C<m> is optional. With the C<m>
-you can use any pair of non-alphanumeric, non-whitespace characters
+you can use any pair of non-whitespace characters
as delimiters. This is particularly useful for matching path names
that contain "/", to avoid LTS (leaning toothpick syndrome). If "?" is
the delimiter, then the match-only-once rule of C<?PATTERN?> applies.
If "'" is the delimiter, no interpolation is performed on the PATTERN.
+When using a character valid in an identifier, whitespace is required
+after the C<m>.
PATTERN may contain variables, which will be interpolated (and the
pattern recompiled) every time the pattern search is evaluated, except
@@ -1381,13 +1383,13 @@ specific options:
e Evaluate the right side as an expression.
ee Evaluate the right side as a string then eval the result
-Any non-alphanumeric, non-whitespace delimiter may replace the
-slashes. If single quotes are used, no interpretation is done on the
-replacement string (the C</e> modifier overrides this, however). Unlike
-Perl 4, Perl 5 treats backticks as normal delimiters; the replacement
-text is not evaluated as a command. If the
-PATTERN is delimited by bracketing quotes, the REPLACEMENT has its own
-pair of quotes, which may or may not be bracketing quotes, e.g.,
+Any non-whitespace delimiter may replace the slashes. Add space after
+the C<s> when using a character allowed in identifiers. If single quotes
+are used, no interpretation is done on the replacement string (the C</e>
+modifier overrides this, however). Unlike Perl 4, Perl 5 treats backticks
+as normal delimiters; the replacement text is not evaluated as a command.
+If the PATTERN is delimited by bracketing quotes, the REPLACEMENT has
+its own pair of quotes, which may or may not be bracketing quotes, e.g.,
C<s(foo)(bar)> or C<< s<foo>/bar/ >>. A C</e> will cause the
replacement portion to be treated as a full-fledged Perl expression
and evaluated right then and there. It is, however, syntax checked at
diff --git a/t/op/subst.t b/t/op/subst.t
index 06c04e8..fe03599 100755
--- a/t/op/subst.t
+++ b/t/op/subst.t
@@ -7,7 +7,7 @@ BEGIN {
}
require './test.pl';
-plan( tests => 139 );
+plan( tests => 140 );
$x = 'foo';
$_ = "x";
@@ -263,6 +263,9 @@ eval 's{foo} # this is a comment, not a delimiter
{bar};';
ok( ! @?, 'parsing of split subst with comment' );
+$snum = eval '$_="exactly"; s sxsys;m 3(yactl)3;$1' #68804
+ok( $snum eq 'yactl', 'alpha delimiters are allowed' );
+
$_="baacbaa";
$snum = tr/a/b/s;
ok( $_ eq "bbcbb" && $snum == 4,
-- "Yes to health care, no to wealth care!" |
From @rgsThanks, applied to bleadperl. 2009/8/30 David Nicol <davidnicol@gmail.com>:
|
@rgs - Status changed from 'open' to 'resolved' |
From @davidnicolOn Sun, Aug 30, 2009 at 7:42 AM, Rafael
this is more thorough, and the test more fun: Inline Patchdiff --git a/pod/perlop.pod b/pod/perlop.pod
index adf0718..31489e1 100644
--- a/pod/perlop.pod
+++ b/pod/perlop.pod
@@ -962,6 +962,9 @@ from the next line. This allows you to write:
s {foo} # Replace foo
{bar} # with bar.
+You can use alphanumerics for quote delimiters too, in which case
+the whitespace is required.
+
The following escape sequences are available in constructs that interpolate
and in transliterations.
X<\t> X<\n> X<\r> X<\f> X<\b> X<\a> X<\e> X<\x> X<\0> X<\c> X<\N>
diff --git a/t/op/subst.t b/t/op/subst.t
index 30af8a2..f1b16ee 100644
--- a/t/op/subst.t
+++ b/t/op/subst.t
@@ -263,8 +263,8 @@ eval 's{foo} # this is a comment, not a delimiter
{bar};';
ok( ! @?, 'parsing of split subst with comment' );
-$snum = eval '$_="exactly"; s sxsys;m 3(yactl)3;$1';
-is( $snum, 'yactl', 'alpha delimiters are allowed' );
+{ my $match = eval '$_= q laurel;y subcostalis;s paperclip;m elite;$&';
+is( $match, 'lit', 'alpha delimiters are allowed' ); }
$_="baacbaa";
$snum = tr/a/b/s; |
Migrated from rt.perl.org#68804 (status was 'resolved')
Searchable as RT68804$
The text was updated successfully, but these errors were encountered: