From: Yitzchak Scott-Thoennes Date: Thu, 18 Mar 2004 22:24:09 +0000 (-0800) Subject: warn on !=~ X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=984200d0e3101dedd636f99bf5d5603033f7162d;p=p5sagit%2Fp5-mst-13.2.git warn on !=~ Message-ID: <20040319062035.GA3768@efn.org> with an improvement suggested by Ton Hospel. p4raw-id: //depot/perl@22542 --- diff --git a/pod/perldiag.pod b/pod/perldiag.pod index e74984c..3132242 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -3444,6 +3444,12 @@ world, because the world might have written on it already. (F) You don't have System V shared memory IPC on your system. +=item !=~ should be !~ + +(W syntax) The non-matching operator is !~, not !=~. !=~ will be +interpreted as the != (numeric not equal) and ~ (1's complement) +operators: probably not what you intended. + =item <> should be quotes (F) You wrote C<< require >> when you should have written diff --git a/t/lib/warnings/toke b/t/lib/warnings/toke index e49376c..f9072ab 100644 --- a/t/lib/warnings/toke +++ b/t/lib/warnings/toke @@ -816,4 +816,22 @@ eval q/5 6/; EXPECT Number found where operator expected at (eval 1) line 1, near "5 6" (Missing operator before 6?) - +######## +# toke.c +use warnings "syntax"; +$_ = $a = 1; +$a !=~ /1/; +$a !=~ m#1#; +$a !=~/1/; +$a !=~ ?/?; +$a != ~/1/; +no warnings "syntax"; +$a !=~ /1/; +$a !=~ m#1#; +$a !=~/1/; +$a !=~ ?/?; +EXPECT +!=~ should be !~ at - line 4. +!=~ should be !~ at - line 5. +!=~ should be !~ at - line 6. +!=~ should be !~ at - line 7. diff --git a/toke.c b/toke.c index a26c724..46aa3aa 100644 --- a/toke.c +++ b/toke.c @@ -3382,8 +3382,20 @@ Perl_yylex(pTHX) case '!': s++; tmp = *s++; - if (tmp == '=') + if (tmp == '=') { + /* was this !=~ where !~ was meant? */ + if (*s == '~' && ckWARN(WARN_SYNTAX)) { + char *t = s+1; + + while (t < PL_bufend && isSPACE(*t)) + ++t; + + if (*t == '/' || (*t == 'm' && !isALNUM(t[1])) || *t == '?') + Perl_warner(aTHX_ packWARN(WARN_SYNTAX), + "!=~ should be !~"); + } Eop(OP_NE); + } if (tmp == '~') PMop(OP_NOT); s--;