perldiag: \%d better written as $%d
authorFather Chrysostomos <sprout@cpan.org>
Sat, 16 Nov 2013 23:12:58 +0000 (15:12 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 17 Nov 2013 21:08:43 +0000 (13:08 -0800)
splain can’t necessarily find it if we hard-code the number:

$ ./perl -Ilib -Mdiagnostics -we '()="" =~ s/()()/\1/r'
\1 better written as $1 at -e line 1 (#1)
    (W syntax) Outside of patterns, backreferences live on as variables.
    The use of backslashes is grandfathered on the right-hand side of a
    substitution, but stylistically it's better to use the variable form
    because other Perl programmers will expect it, and it works better if
    there are more than 9 backreferences.

$ ./perl -Ilib -Mdiagnostics -we '()="" =~ s/()()/\2/r'
\2 better written as $2 at -e line 1.
$

%d is more intuitive than %c here, so I used %d in the pod instead of
copying the C code that generates it.

pod/perldiag.pod
t/porting/diag.t
toke.c

index 9f07683..53f5e68 100644 (file)
@@ -489,7 +489,7 @@ occurred.  Since the intended environment for the C<BEGIN {}> could not
 be guaranteed (due to the errors), and since subsequent code likely
 depends on its correct operation, Perl just gave up.
 
-=item \1 better written as $1
+=item \%d better written as $%d
 
 (W syntax) Outside of patterns, backreferences live on as variables.
 The use of backslashes is grandfathered on the right-hand side of a
index 8dece71..df6e1b3 100644 (file)
@@ -472,7 +472,6 @@ Can't %s script `%s' with ARGV[0] being `%s'
 Can't %s "%s": %s
 Can't %s `%s' with ARGV[0] being `%s' (looking for executables only, not found)
 Can't use string ("%s"%s) as a subroutine ref while "strict refs" in use
-\%c better written as $%c
 Character(s) in '%c' format wrapped in %s
 chown not implemented!
 clear %s
diff --git a/toke.c b/toke.c
index cd653dd..efb6533 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -3379,6 +3379,7 @@ S_scan_const(pTHX_ char *start)
            if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
                isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
            {
+               /* diag_listed_as: \%d better written as $%d */
                Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
                *--s = '$';
                break;