From: David Nicol Date: Sun, 30 Aug 2009 12:41:21 +0000 (+0200) Subject: Document better what is allowed as regex delimiters X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ed02a3bf5adcb3fb74cb46557427f6afdc14e80c;p=p5sagit%2Fp5-mst-13.2.git Document better what is allowed as regex delimiters Identifier characters are allowed. Also add a test --- diff --git a/pod/perlop.pod b/pod/perlop.pod index 1df9fcb..adf0718 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -1152,11 +1152,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 is optional. With the C -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 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. PATTERN may contain variables, which will be interpolated (and the pattern recompiled) every time the pattern search is evaluated, except @@ -1366,13 +1368,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 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 when using a character allowed in identifiers. If single quotes +are used, no interpretation is done on the replacement string (the C +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 or C<< s/bar/ >>. A C 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..30af8a2 100644 --- 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'; +is( $snum, 'yactl', 'alpha delimiters are allowed' ); + $_="baacbaa"; $snum = tr/a/b/s; ok( $_ eq "bbcbb" && $snum == 4,