Revised PATCH: [perl #75642] Deprecate not having space between pattern and following word
[email protected] (karl williamson)
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
> > Things like "/foo/sand bar" will now generate a deprecated warning. > > I don't think there was any complaint in our discussions of new modifier > letters about deprecating words following a pattern without a gap. I > think the above example further shows the problem with the current behavior. > > This simple patch deprecates this usage. It does add an extra message > if the following word isn't legitimate to the syntax error that comes > out next, but I don't think that's worth worrying about, and may give > someone a further clue as to where on the line the problem is. > This patch is revised to use t/lib/warnings for testing; slightly different message wording.
0001-Deprecate-no-space-between-pattern-following-word.patch
(text/x-patch, 2.8 KB)
From dd805fc6a599d235f66afad9c72fc4248c27a7d0 Mon Sep 17 00:00:00 2001
From: Karl Williamson <khw@khw-desktop.(none)>
Date: Wed, 9 Jun 2010 14:40:14 -0600
Subject: [PATCH] Deprecate no space between pattern, following word
This patch raises a deprecated warning on constructs like
$result = $a =~ m/$foo/sand $bar;
which means
$result = $a =~ m/$foo/s and $bar;
---
pod/perldiag.pod | 18 +++++++++++++++++-
t/lib/warnings/toke | 5 ++++-
toke.c | 6 ++++++
3 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 4d7d6ad..26c35a0 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -1913,6 +1913,23 @@ spots. This is now heavily deprecated.
(F) The parser has given up trying to parse the program after 10 errors.
Further error messages would likely be uninformative.
+=item Having no space between pattern and following word is deprecated
+
+(D syntax)
+
+You had a word that isn't a regex modifier immediately following a pattern
+without an intervening space. For example, the two constructs:
+
+ $a =~ m/$foo/sand $bar
+ $a =~ m/$foo/s and $bar
+
+both currently mean the same thing, but it is planned to disallow the first form
+in Perl 5.16. And,
+
+ $a =~ m/$foo/and $bar
+
+will be disallowed too.
+
=item Hexadecimal number > 0xffffffff non-portable
(W portable) The hexadecimal number you specified is larger than 2**32-1
@@ -2855,7 +2872,6 @@ your system.
(F) The indicated command line switch needs a mandatory argument, but
you haven't specified one.
-
=item No such class field "%s" in variable %s of type %s
(F) You tried to access a key from a hash through the indicated typed variable
diff --git a/t/lib/warnings/toke b/t/lib/warnings/toke
index 2236442..6a1a6a5 100644
--- a/t/lib/warnings/toke
+++ b/t/lib/warnings/toke
@@ -140,13 +140,16 @@ Use of comma-less variable list is deprecated at - line 4.
Use of comma-less variable list is deprecated at - line 4.
########
# toke.c
+$a =~ m/$foo/sand $bar;
$a = <<;
no warnings 'deprecated' ;
+$a =~ m/$foo/sand $bar;
$a = <<;
EXPECT
-Use of bare << to mean <<"" is deprecated at - line 2.
+Having no space between pattern and following word is deprecated at - line 2.
+Use of bare << to mean <<"" is deprecated at - line 3.
########
# toke.c
use warnings 'syntax' ;
diff --git a/toke.c b/toke.c
index daa60a1..a94753a 100644
--- a/toke.c
+++ b/toke.c
@@ -11887,6 +11887,12 @@ S_scan_pat(pTHX_ char *start, I32 type)
#endif
while (*s && strchr(valid_flags, *s))
pm->op_pmflags = S_pmflag(pm->op_pmflags, *s++);
+
+ if (isALNUM(*s)) {
+ Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX),
+ "Having no space between pattern and following word is deprecated");
+
+ }
#ifdef PERL_MAD
if (PL_madskills && modstart != s) {
SV* tmptoken = newSVpvn(modstart, s - modstart);
--
1.5.6.3