Message-ID: <
20080724181427.aiml4sdvr40k4coc@horde.wizbit.be>
Note that the Subject: has a typo - it should be $\
This adds a new warning.
I moved the tests from the original patch to t/lib/warnings/toke.
p4raw-id: //depot/perl@34224
literal @foo, then write it as \@foo; otherwise find out what happened
to the array you apparently lost track of.
+=item Possible unintended interpolation of $\ in regex
+
+(W ambiguous) You said something like C<m/$\/> in a regex.
+The regex C<m/foo$\s+bar/m> translates to: match the word 'foo', the output
+record separartor (see L<perlvar/$\>) and the letter 's' (one time or more)
+followed by the word 'bar'.
+
+If this is what you intended then you can silence the warning by using
+C<m/${\}/> (for example: C<m/foo${\}s+bar/>).
+
+If instead you intended to match the word 'foo' at the end of the line
+followed by whitespace and the word 'bar' on the next line then you can use
+C<m/$(?)\/> (for example: C<m/foo$(?)\s+bar/>).
+
=item pragma "attrs" is deprecated, use "sub NAME : ATTRS" instead
(D deprecated) You have written something like this:
Prototype after '%' for main::proto_after_hash : %$ at - line 7.
Illegal character after '_' in prototype for main::underscore_fail : $_$ at - line 12.
Prototype after '@' for main::underscore_after_at : @_ at - line 13.
+########
+# toke.c
+use warnings "ambiguous";
+"foo\nn" =~ /^foo$\n/;
+"foo\nn" =~ /^foo${\}n/;
+my $foo = qr/^foo$\n/;
+my $bar = qr/^foo${\}n/;
+no warnings "ambiguous";
+"foo\nn" =~ /^foo$\n/;
+"foo\nn" =~ /^foo${\}n/;
+my $foo = qr/^foo$\n/;
+my $bar = qr/^foo${\}n/;
+EXPECT
+Possible unintended interpolation of $\ in regex at - line 3.
+Possible unintended interpolation of $\ in regex at - line 5.
else if (*s == '$') {
if (!PL_lex_inpat) /* not a regexp, so $ must be var */
break;
- if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
+ if (s + 1 < send && !strchr("()| \r\n\t", s[1])) {
+ if (s[1] == '\\' && ckWARN(WARN_AMBIGUOUS)) {
+ Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
+ "Possible unintended interpolation of $\\ in regex");
+ }
break; /* in regexp, $ might be tail anchor */
+ }
}
/* End of else if chain - OP_TRANS rejoin rest */