From: Mark-Jason Dominus Date: Mon, 1 Apr 2002 13:22:01 +0000 (-0500) Subject: warning for split(/.../g, ...); X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f34840d8d697d9f8be532dea1352cc0aeefc696b;p=p5sagit%2Fp5-mst-13.2.git warning for split(/.../g, ...); Message-ID: <20020401182201.21189.qmail@plover.com> p4raw-id: //depot/perl@15663 --- diff --git a/op.c b/op.c index 9b07a2f..e7f1042 100644 --- a/op.c +++ b/op.c @@ -6658,6 +6658,10 @@ Perl_ck_split(pTHX_ OP *o) kid->op_type = OP_PUSHRE; kid->op_ppaddr = PL_ppaddr[OP_PUSHRE]; scalar(kid); + if (ckWARN(WARN_REGEXP) && ((PMOP *)kid)->op_pmflags & PMf_GLOBAL) { + Perl_warner(aTHX_ packWARN(WARN_REGEXP), + "Use of /g modifier is meaningless in split"); + } if (!kid->op_sibling) append_elem(OP_SPLIT, o, newDEFSVOP()); diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 27823a7..f5d98ef 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -559,8 +559,12 @@ The command-line options -s and -F are now recognized on the shebang Use of the C match modifier without an accompanying C modifier elicits a new warning: C. + Use of C in substitutions, even with C, elicits -C. +C. + +Use of C with C elicits . =back diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 35f26c4..08f342a 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -3996,6 +3996,12 @@ modifier is not presently meaningful in substitutions. use the /g modifier. Currently, /c is meaningful only when /g is used. (This may change in the future.) +=item Use of /g modifier is meaningless in split + +(W regexp) You used the /g modifier on the pattern for a C +operator. Since C always tries to match the pattern +repeatedly, the C has no effect. + =item Use of *glob{FILEHANDLE} is deprecated (D deprecated) You are now encouraged to use the shorter *glob{IO} form diff --git a/t/lib/warnings/op b/t/lib/warnings/op index ff00dcd..7833562 100644 --- a/t/lib/warnings/op +++ b/t/lib/warnings/op @@ -111,6 +111,8 @@ Package `%s' not found (did you use the incorrect case?) + Use of /g modifier is meaningless in split + Mandatory Warnings ------------------ Prototype mismatch: [cv_ckproto] @@ -952,3 +954,12 @@ EXPECT Use of "package" with no arguments is deprecated at - line 3. Global symbol "BEGIN" requires explicit package name at - line 4. BEGIN not safe after errors--compilation aborted at - line 4. +######## +# op.c +# 20020401 mjd@plover.com at suggestion of jfriedl@yahoo.com +use warnings 'regexp'; +split /blah/g, "blah"; +no warnings 'regexp'; +split /blah/g, "blah"; +EXPECT +Use of /g modifier is meaningless in split at - line 4.